Spring配置文件
<?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: tx= " http://www.springframework.org/schema/tx"
xmlns: aop= " http://www.springframework.org/schema/aop"
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/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd" >
< context: component-scan base-package = " service" use-default-filters = " true" >
< context: exclude-filter type = " annotation" expression = " org.springframework.stereotype.Controller" />
</ context: component-scan>
< context: property-placeholder location = " classpath:jdbc.properties" />
< bean id = " dataSource" class = " com.alibaba.druid.pool.DruidDataSource" >
< property name = " driverClassName" value = " ${jdbc.driverClass}" />
< property name = " url" value = " ${jdbc.url}" />
< property name = " username" value = " ${jdbc.username}" />
< property name = " password" value = " ${jdbc.password}" />
</ bean>
< bean id = " sqlSessionFactory" class = " org.mybatis.spring.SqlSessionFactoryBean" >
< property name = " dataSource" ref = " dataSource" />
< property name = " mapperLocations" >
< list>
< value> classpath:mapper/*.xml</ value>
</ list>
</ property>
< property name = " typeAliasesPackage" value = " entity" />
< property name = " plugins" >
< array>
< bean class = " com.github.pagehelper.PageInterceptor" />
</ array>
</ property>
</ bean>
< bean id = " mapperScannerConfigurer" class = " org.mybatis.spring.mapper.MapperScannerConfigurer" >
< property name = " basePackage" value = " mapper" />
< property name = " sqlSessionFactoryBeanName" value = " sqlSessionFactory" />
</ bean>
< bean id = " txManager" class = " org.springframework.jdbc.datasource.DataSourceTransactionManager" >
< property name = " dataSource" ref = " dataSource" />
</ bean>
< tx: advice id = " txAdvice" transaction-manager = " txManager" >
< tx: attributes>
< tx: method name = " query*" read-only = " true" propagation = " SUPPORTS" />
< tx: method name = " select*" read-only = " true" propagation = " SUPPORTS" />
< tx: method name = " get*" read-only = " true" propagation = " SUPPORTS" />
< tx: method name = " find*" read-only = " true" propagation = " SUPPORTS" />
< tx: method name = " *" read-only = " false" propagation = " REQUIRED" rollback-for = " Exception" />
</ tx: attributes>
</ tx: advice>
< aop: config>
< aop: pointcut id = " pt" expression = " execution(* service..*.*(..))" />
< aop: advisor advice-ref = " txAdvice" pointcut-ref = " pt" />
</ aop: config>
</ beans>
Spring MVC配置文件
<?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 = " controller" use-default-filters = " false" >
< context: include-filter type = " annotation" expression = " org.springframework.stereotype.Controller" />
</ context: component-scan>
< mvc: annotation-driven/>
< mvc: default-servlet-handler/>
< bean class = " org.springframework.web.servlet.view.InternalResourceViewResolver" >
< property name = " prefix" value = " /" />
< property name = " suffix" value = " .jsp" />
</ bean>
</ beans>
WEB-INF/web.xml配置文件
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
< web-app>
< display-name> Archetype Created Web Application</ display-name>
< filter>
< filter-name> character</ 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> character</ filter-name>
< url-pattern> /*</ url-pattern>
</ filter-mapping>
< servlet>
< servlet-name> MyMVC</ servlet-name>
< servlet-class> org.springframework.web.servlet.DispatcherServlet</ servlet-class>
< init-param>
< param-name> contextConfigLocation</ param-name>
< param-value> classpath:springmvc.xml</ param-value>
</ init-param>
< load-on-startup> 1</ load-on-startup>
</ servlet>
< servlet-mapping>
< servlet-name> MyMVC</ servlet-name>
< url-pattern> /</ url-pattern>
</ servlet-mapping>
</ web-app>