1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans xmlns="http://www.springframework.org/schema/beans"
3 xmlns:context="http://www.springframework.org/schema/context"
4 xmlns:mvc="http://www.springframework.org/schema/mvc"
5 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6 xsi:schemaLocation="
7 http://www.springframework.org/schema/beans
8 http://www.springframework.org/schema/beans/spring-beans.xsd
9 http://www.springframework.org/schema/context
10 http://www.springframework.org/schema/context/spring-context.xsd
11 http://www.springframework.org/schema/mvc
12 http://www.springframework.org/schema/mvc/spring-mvc.xsd">
13 <!-- 开启注解扫描 只要在当前包下面的子包和类,都会被扫描到 -->
14 <context:component-scan base-package="cn.itsource.controller"></context:component-scan>
15
16 <!-- 视图解析器 -->
17 <bean id="resourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
18 <property name="prefix" value="/WEB-INF/views/"></property>
19 <property name="suffix" value=".jsp"></property>
20 </bean>
21
22
23 <!-- 放行静态资源 -->
24 <mvc:default-servlet-handler/>
25 <!-- 使支持@RequestMapping注解 -->
26 <mvc:annotation-driven/>
27 </beans>
1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans xmlns="http://www.springframework.org/schema/beans"
3 xmlns:context="http://www.springframework.org/schema/context"
4 xmlns:mvc="http://www.springframework.org/schema/mvc"
5 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6 xsi:schemaLocation="
7 http://www.springframework.org/schema/beans
8 http://www.springframework.org/schema/beans/spring-beans.xsd
9 http://www.springframework.org/schema/context
10 http://www.springframework.org/schema/context/spring-context.xsd
11 http://www.springframework.org/schema/mvc
12 http://www.springframework.org/schema/mvc/spring-mvc.xsd">
13 <!-- spring的测试方法(时间测试) -->
14 <bean id="date" class="java.util.Date"></bean>
15 <!-- 因为将mybatis配置文件整合到spring中 所以配置加载属性 -->
16 <context:property-placeholder location="classpath:jdbc.properties"/>
17 <!-- 管理数据源 -->
18 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource ">
19 <property name="username" value="${jdbc.username}"></property>
20 <property name="password" value="${jdbc.password}"></property>
21 <property name="url" value="${jdbc.url}"></property>
22 <property name="driverClassName" value="${jdbc.driverClassName}"></property>
23 </bean>
24
25
26 <!-- 将sqlSessionFactory交给spring去管理 -->
27 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
28 <!-- 注入数据源,因为获取连接之后,才能打开会话 -->
29 <property name="dataSource" ref="dataSource"></property>
30
31 <!-- 加载所有mapper.xml映射文件文件 -->
32 <property name="mapperLocations" value="classpath:cn/itsource/mapper/*Mapper.java"></property>
33 </bean>
34
35
36 <!-- 将Mapper接口交给Spring去管理 -->
37 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
38 <!-- 指定mapper接口的包路径 -->
39 <property name="basePackage" value="cn.itsource.mapper"></property>
40 </bean>
41
42 <!-- 5.扫描包路径 -->
43 <context:component-scan base-package="cn.itsource.service"></context:component-scan>
44
45
46
47
48
49
50 </beans>
1 <?xml version="1.0" encoding="UTF-8"?>
2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
3 <display-name>0721</display-name>
4 <!-- 加载applicationContext.xml -->
5 <listener>
6 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
7 </listener>
8 <!-- 加载spring的配置文件 -->
9 <context-param>
10 <param-name>contextConfigLocation</param-name>
11 <param-value>classpath:applicationContext.xml</param-value>
12 </context-param>
13 <!-- 配置前端控制器 -->
14 <servlet>
15 <servlet-name>dispatcherServlet</servlet-name>
16 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
17 <!-- 加载核心配置文件 -->
18 <init-param>
19 <param-name>contextConfigLocation</param-name>
20 <param-value>classpath:applicationContext-mvc.xml</param-value>
21 </init-param>
22 <load-on-startup>1</load-on-startup>
23 </servlet>
24
25 <servlet-mapping>
26 <servlet-name>dispatcherServlet</servlet-name>
27 <url-pattern>/</url-pattern>
28 </servlet-mapping>
29 <!-- 配置过滤器,处理字符集编码问题 -->
30 <filter>
31 <filter-name>characterEncoding</filter-name>
32 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
33 <init-param>
34 <param-name>encoding</param-name>
35 <param-value>UTF-8</param-value>
36 </init-param>
37 <!--强制指定字符编码,即使request或response设置了字符编码,也会强制使用当前设置的,任何情况下强制使用此编码-->
38 <init-param>
39 <param-name>forceEncoding</param-name>
40 <param-value>true</param-value>
41 </init-param>
42 </filter>
43 <filter-mapping>
44 <filter-name>characterEncoding</filter-name>
45 <url-pattern>/*</url-pattern>
46 </filter-mapping>
47 </web-app>