欢迎来到刘认真的博客

It's not me that's wrong. It's the whole world

springmvc web.xml和application.xml配置详情(附:完整版pom.xml)

 

web.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns="http://java.sun.com/xml/ns/javaee"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
 5          version="3.0">
 6     <!-- 加载applicationContext.xml配置文件 -->
 7     <context-param>
 8         <param-name>contextConfigLocation</param-name>
 9         <param-value>classpath:applicationContext.xml</param-value>
10     </context-param>
11     <!-- 设置编码为UTF-8 -->
12     <filter>
13         <description>字符集过滤器</description>
14         <filter-name>encodingFilter</filter-name>
15         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
16         <init-param>
17             <description>字符集编码</description>
18             <param-name>encoding</param-name>
19             <param-value>UTF-8</param-value>
20         </init-param>
21     </filter>
22     <filter-mapping>
23         <filter-name>encodingFilter</filter-name>
24         <url-pattern>/*</url-pattern>
25     </filter-mapping>
26 
27     <!-- spring监听器 -->
28     <listener>
29         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
30     </listener>
31 
32     <listener>
33         <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
34     </listener>
35 
36     <!-- 配置Servlet -->
37     <servlet>
38         <servlet-name>springmvc</servlet-name>
39         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
40         <init-param>
41             <param-name>contextConfigLocation</param-name>
42             <param-value>classpath:springmvc.xml</param-value>
43         </init-param>
44         <load-on-startup>1</load-on-startup>
45     </servlet>
46 
47     <servlet-mapping>
48         <servlet-name>springmvc</servlet-name>
49         <url-pattern>*.do</url-pattern>
50     </servlet-mapping>
51 
52 
53     <!-- 程序加载时的页面 -->
54     <welcome-file-list>
55         <welcome-file>/index.jsp</welcome-file>
56     </welcome-file-list>
57 
58 </web-app>
59 <!-- 多部分文件上传 M kb byte-->
60 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
61 <property name="maxUploadSize" value="104857600"/>
62 <property name="defaultEncoding" value="UTF-8"></property>
63 </bean>
64
65 <!--处理静态文件 -->
66 <mvc:resources location="/js/" mapping="/js/**"/>
67 <mvc:resources location="/css/" mapping="/css/**"/
68 <mvc:resources location="/img/" mapping="/img/**"/>

 

application.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4        xmlns:context="http://www.springframework.org/schema/context"
 5        xmlns:mvc="http://www.springframework.org/schema/mvc"
 6        xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
 7         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
 8         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
 9 
10     <!-- 自动扫描controller包下的所有类,使其认为spring mvc的控制器 -->
11     <context:component-scan base-package="com.xf"/>
12     <mvc:annotation-driven/>
13 
14     <!-- 逻辑视图与物理视图的映射 -->
15     <bean
16             class="org.springframework.web.servlet.view.InternalResourceViewResolver">
17         <property name="prefix" value="/WEB-INF/user/"></property>
18         <property name="suffix" value=".jsp"></property>
19     </bean>
20 
21 </beans>

 

 

 

完整版pom.xml

  1 <?xml version="1.0" encoding="UTF-8"?>
  2 
  3 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  5 
  6     <modelVersion>4.0.0</modelVersion>
  7     <packaging>war</packaging>
  8     <name>SpringIbatisMaven</name>
  9     <groupId>etc.com</groupId>
 10     <artifactId>SpringIbatisMaven</artifactId>
 11     <version>1.0-SNAPSHOT</version>
 12     <url>http://maven.apache.org</url>
 13 
 14     <properties>
 15         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 16         <maven.compiler.source>1.7</maven.compiler.source>
 17         <maven.compiler.target>1.7</maven.compiler.target>
 18         <spring.version>4.3.24.RELEASE</spring.version>
 19         <mybatis.version>3.5.1</mybatis.version>
 20         <mybatis-spring.version>1.3.2</mybatis-spring.version>
 21     </properties>
 22     <dependencies>
 23         <!--白盒测试工具 -->
 24         <dependency>
 25             <groupId>junit</groupId>
 26             <artifactId>junit</artifactId>
 27             <version>4.12</version>
 28         </dependency>
 29         <!--控制日志信息输送的目的地是控制台、文件、GUI组件、甚至是套接口服务器 -->
 30         <dependency>
 31             <groupId>log4j</groupId>
 32             <artifactId>log4j</artifactId>
 33             <version>1.2.17</version>
 34         </dependency>
 35         <dependency>
 36             <groupId>org.slf4j</groupId>
 37             <artifactId>slf4j-api</artifactId>
 38             <version>1.7.5</version>
 39         </dependency>
 40         <!--解析json -->
 41         <dependency>
 42             <groupId>org.codehaus.jackson</groupId>
 43             <artifactId>jackson-mapper-asl</artifactId>
 44             <version>1.9.12</version>
 45         </dependency>
 46         <!--处理编码 -->
 47         <dependency>
 48             <groupId>commons-codec</groupId>
 49             <artifactId>commons-codec</artifactId>
 50             <version>1.7</version>
 51         </dependency>
 52         <!-- mybatis是ibatis 的升级版。是一种 orm 工具,简化数据库操作 -->
 53         <dependency>
 54             <groupId>org.mybatis</groupId>
 55             <artifactId>mybatis</artifactId>
 56             <version>${mybatis.version}</version>
 57         </dependency>
 58         <!-- 是一个用来整合 MyBatis 和 Spring 框架的小类库 -->
 59         <dependency>
 60             <groupId>org.mybatis</groupId>
 61             <artifactId>mybatis-spring</artifactId>
 62             <version>${mybatis-spring.version}</version>
 63         </dependency>
 64 
 65         <!--用来帮助进行IO功能开发 -->
 66         <dependency>
 67             <groupId>commons-io</groupId>
 68             <artifactId>commons-io</artifactId>
 69             <version>2.0.1</version>
 70         </dependency>
 71         <!-- Spring -->
 72         <dependency>
 73             <groupId>org.springframework</groupId>
 74             <artifactId>spring-core</artifactId>
 75             <version>${spring.version}</version>
 76         </dependency>
 77         <dependency>
 78             <groupId>org.springframework</groupId>
 79             <artifactId>spring-context</artifactId>
 80             <version>${spring.version}</version>
 81         </dependency>
 82         <dependency>
 83             <groupId>org.springframework</groupId>
 84             <artifactId>spring-web</artifactId>
 85             <version>${spring.version}</version>
 86         </dependency>
 87         <dependency>
 88             <groupId>org.springframework</groupId>
 89             <artifactId>spring-context-support</artifactId>
 90             <version>${spring.version}</version>
 91         </dependency>
 92         <dependency>
 93             <groupId>org.springframework</groupId>
 94             <artifactId>spring-webmvc</artifactId>
 95             <version>${spring.version}</version>
 96         </dependency>
 97         <dependency>
 98             <groupId>org.springframework</groupId>
 99             <artifactId>spring-test</artifactId>
100             <version>${spring.version}</version>
101         </dependency>
102         <!-- aop -->
103         <dependency>
104             <groupId>org.springframework</groupId>
105             <artifactId>spring-aop</artifactId>
106             <version>${spring.version}</version>
107         </dependency>
108         <dependency>
109             <groupId>org.aspectj</groupId>
110             <artifactId>aspectjweaver</artifactId>
111             <version>1.8.13</version>
112         </dependency>
113         <dependency>
114             <groupId>cglib</groupId>
115             <artifactId>cglib</artifactId>
116             <version>3.2.4</version>
117         </dependency>
118         <!--tx-->
119         <dependency>
120             <groupId>org.springframework</groupId>
121             <artifactId>spring-orm</artifactId>
122             <version>${spring.version}</version>
123         </dependency>
124         <dependency>
125             <groupId>org.springframework</groupId>
126             <artifactId>spring-tx</artifactId>
127             <version>${spring.version}</version>
128         </dependency>
129         <!-- jackson -->
130         <dependency>
131             <groupId>com.fasterxml.jackson.core</groupId>
132             <artifactId>jackson-core</artifactId>
133             <version>2.9.3</version>
134         </dependency>
135         <dependency>
136             <groupId>com.fasterxml.jackson.core</groupId>
137             <artifactId>jackson-annotations</artifactId>
138             <version>2.9.3</version>
139         </dependency>
140         <dependency>
141             <groupId>com.fasterxml.jackson.core</groupId>
142             <artifactId>jackson-databind</artifactId>
143             <version>2.9.3</version>
144         </dependency>
145         <!-- jdbc driver -->
146         <dependency>
147             <groupId>mysql</groupId>
148             <artifactId>mysql-connector-java</artifactId>
149             <version>5.1.22</version>
150         </dependency>
151         <!-- JSTL(JSP Standard Tag Library ,JSP标准标签库)是一个不断完善的开放源代码的JSP标签 -->
152         <dependency>
153             <groupId>javax.servlet</groupId>
154             <artifactId>jstl</artifactId>
155             <version>1.2</version>
156         </dependency>
157         <!-- Servlet包含的类以及方法 -->
158         <dependency>
159             <groupId>javax.servlet</groupId>
160             <artifactId>servlet-api</artifactId>
161             <version>2.5</version>
162         </dependency>
163     </dependencies>
164 </project>

 

posted @ 2019-07-16 11:19  刘认真  阅读(3520)  评论(0编辑  收藏  举报