groupId | artifactId |
org.springframework | spring-context(自动依赖core,beans,aop,expression) |
org.springframework | spring-web(自动依赖core,beans) |
org.springframework | spring-webmvc(自动依赖以上全部) |
org.springframework | spring-aspects(自动依赖aspectjweaver) |
org.springframework | spring-jdbc(自动依赖core,beans,tx) |
org.mybatis | mybatis-spring(整合核心包) |
org.mybatis | mybatis(mybatis核心包) |
mysql | mysql-connector-java(驱动包) |
c3p0 | c3p0(数据库连接池) |
org.slf4j | slf4j-jdk14(日志接口) |
log4j | log4j(日志实现) |
org.apache.tomcat | tomcat-jsp-api |
jstl | jstl(自定义标签) |
org.codehaus.jackson | jackson-core-asl(json工具包) |
junit | junit |
文件配置:
web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext*.xml</param-value>
</context-param>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
applicationContex.xml
<context:property-placeholder location="classpath:resource/*.properties" />
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
p:user="${jdbc.user}" p:password="${jdbc.password}" p:jdbcUrl="${jdbc.jdbcUrl}"
p:driverClass="${jdbc.driverClass}" />
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
p:configLocation="classpath:mybatis/SqlMapConfig.xml"
p:dataSource-ref="dataSource" />
<bean class="org.mybatis.spring.MapperScannerConfigurer"
p:basePackage="mapper" />
<!-- 事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 传播行为 -->
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
<tx:method name="select*" propagation="SUPPORTS" read-only="true" />
<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 切面 -->
<aop:config>
<aop:advisor advice-ref="txAdvice"
pointcut="execution(* com.taotao.service.*.*(..))" />
</aop:config>
SqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
</configuration>