使用springMVC所需要的pom配置
程序员文章站
2022-03-23 23:24:27
目录springmvc所需要的pom配置springmvc 基本pom依赖及配置文件spring mvc pom依赖springmvc所需要的pom配置配置应用的字符编码格式
springmvc所需要的pom配置
配置应用的字符编码格式
<properties> <project.build.sourceencoding>utf-8</project.build.sourceencoding> <project.reporting.outputencoding>utf-8</project.reporting.outputencoding> <maven.compiler.encoding>utf-8</maven.compiler.encoding> </properties>
servlet api的maven依赖
<dependency> <groupid>javax.servlet</groupid> <artifactid>javax.servlet-api</artifactid> <version>3.1.0</version> <scope>provided</scope> </dependency>
javaservlet page api(jsp api)的maven依赖
<dependency> <groupid>javax.servlet.jsp</groupid> <artifactid>javax.servlet.jsp-api</artifactid> <version>2.3.1</version> <scope>provided</scope> </dependency>
jstl的maven依赖
<dependency> <groupid>javax.servlet</groupid> <artifactid>jstl</artifactid> <version>1.2</version> </dependency>
spring-webmvc的maven依赖
<dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> <version>5.1.0.release</version> </dependency>
commons-lang3的依赖
<dependency> <groupid>org.apache.commons</groupid> <artifactid>commons-lang3</artifactid> <version>3.8.1</version> </dependency>
hibernate-validator
<dependency> <groupid>org.hibernate.validator</groupid> <artifactid>hibernate-validator</artifactid> <version>6.0.13.final</version> </dependency>
应用版本跟jetty配置
<build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>3.8.0</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupid>org.eclipse.jetty</groupid> <artifactid>jetty-maven-plugin</artifactid> <version>9.3.7.v20160115</version> <configuration> <webapp> <contextpath>/test</contextpath> </webapp> <scanintervalseconds>10</scanintervalseconds> </configuration> </plugin> </plugins> </build>
springmvc 基本pom依赖及配置文件
spring mvc pom依赖
<dependencies> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>4.12</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> <version>5.1.19.release</version> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>servlet-api</artifactid> <version>2.2</version> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>jstl</artifactid> <version>1.2</version> </dependency> <dependency> <groupid>org.projectlombok</groupid> <artifactid>lombok</artifactid> <version>1.18.18</version> </dependency> <dependency> <groupid>com.fasterxml.jackson.core</groupid> <artifactid>jackson-core</artifactid> <version>2.11.0</version> </dependency> <dependency> <groupid>com.fasterxml.jackson.core</groupid> <artifactid>jackson-databind</artifactid> <version>2.11.0</version> </dependency> <dependency> <groupid>com.fasterxml.jackson.core</groupid> <artifactid>jackson-annotations</artifactid> <version>2.11.0</version> </dependency> </dependencies>
application.xml
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- 自动扫描指定的包,下面所有注解类交给ioc容器管理 --> <context:component-scan base-package="controller"/> <!--静态资源过滤--> <mvc:default-servlet-handler /> <!--json乱码问题配置--> <mvc:annotation-driven> <mvc:message-converters register-defaults="true"> <bean class="org.springframework.http.converter.stringhttpmessageconverter"> <constructor-arg value="utf-8"/> </bean> <bean class="org.springframework.http.converter.json.mappingjackson2httpmessageconverter"> <property name="objectmapper"> <bean class="org.springframework.http.converter.json.jackson2objectmapperfactorybean"> <property name="failonemptybeans" value="false"/> </bean> </property> </bean> </mvc:message-converters> </mvc:annotation-driven> <!-- 视图解析器 --> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver" id="internalresourceviewresolver"> <!-- 前缀 --> <property name="prefix" value="/web-inf/jsp/" /> <!-- 后缀 --> <property name="suffix" value=".jsp" /> </bean> </beans>
web.xml
<?xml version="1.0" encoding="utf-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value>classpath:application.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- 乱码过滤器--> <filter> <filter-name>encoding</filter-name> <filter-class>org.springframework.web.filter.characterencodingfilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
推荐阅读
-
在eclipse中使用Maven分模块搭建SSM框架,创建jar、war、pom工程模块教学,项目的热部署,需要的可以留下邮箱,给大家发整理过的Maven笔记
-
为什么使用Maven构建项目就需要在pom.xml中配置Servlet依赖
-
IDEA 使用springMVC在配置完web.xml后,依旧存在中文乱码的问题
-
使用springMVC所需要的pom配置
-
maven项目使用本地jar的pom配置方式
-
在eclipse中使用Maven分模块搭建SSM框架,创建jar、war、pom工程模块教学,项目的热部署,需要的可以留下邮箱,给大家发整理过的Maven笔记
-
使用SPFILE将所配置的初始化参数重置为系统默认值
-
使用SPFILE将所配置的初始化参数重置为系统默认值
-
使用maven打包包含依赖jar文件的jar包pom配置
-
使用springMVC所需要的pom配置