<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
">
<!--1.扫描spring包-->
<context:component-scan base-package="com.hgd.oa.*"/>
<!--2.加载jdbc.properties-->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!--3.加载数据源-->
<bean id="database" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${jdbc.Driver}"/>
<property name="url" value="${jdbc.Url}"/>
<property name="username" value="${jdbc.Username}"/>
<property name="password" value="${jdbc.Password}"/>
</bean>
<!--4.整合mybatis,获取SqlSession工厂 SqlSessionFactoryBean整合mybatis生成SqlSession工厂-->
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<!--整合数据源-->
<property name="dataSource" ref="database"/>
<!--指定mybatis的mapper映射文件的位置-->
<property name="mapperLocations" value="classcom/hgd/oa/mapper/*.xml"/>
<!--给实体类取别名-->
<property name="typeAliasesPackage" value="com.hgd.oa.pojo"/>
</bean>
<!--5.配置Mybatis的接口层-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--spring指定mybatis的mapper层-->
<property name="basePackage" value="com.hgd.oa.mapper"/>
</bean>
<!--6.配置声明式事务(mybtais的事物管理器)-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="database"/>
</bean>
<!--7.开启注解事物管理-->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
<?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
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--扫描包-->
<context:component-scan base-package="com.hgd.oa.controller"/>
<!--释放静态资源-->
<mvc:default-servlet-handler/>
<mvc:annotation-driven/>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<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"
version="3.1">
<display-name>Archetype Created Web Application</display-name>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<!--指定Spring配置文件的地址-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!--SpringMvc请求乱码处理-->
<filter>
<filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--SpringMvc请求乱码处理-->
<!--配置一个Spring的监听器,WEB项目一旦启动,那么Spring框架就会自动启动-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--前端控制器(DispatcherServlet)-->
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<!--DispatcherServlet类全路径-->
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--指定SpringMvc的配置文件位置-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<!--设置Servlet创建对象的时机,默认是第一次访问创建对象,如果设置那么服务器一旦启动就创建Servlet对象!-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<!--不能写/*,必须写/,这是REST URL风格的要求,REST风格会在后面介绍 -->
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>