spring中使用TransactionInterceptor拦截器和BeanNameAutoProxyCreator处理事务案例

本文主要是介绍spring中使用TransactionInterceptor拦截器和BeanNameAutoProxyCreator处理事务案例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

项目结构图

在这里插入图片描述

web.xml

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version="3.0"metadata-complete="true"><display-name>Archetype Created Web Application</display-name><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc-servlet.xml</param-value></init-param></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><init-param><param-name>encoding</param-name><param-value>utf-8</param-value></init-param><init-param><param-name>forceEncoding</param-name><param-value>true</param-value></init-param></filter><filter-mapping><filter-name>characterEncodingFilter</filter-name><url-pattern>/</url-pattern></filter-mapping></web-app>

springmvc-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:context="http://www.springframework.org/schema/context"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:http="http://www.springframework.org/schema/c"xsi:schemaLocation="http://www.springframework.org/schema/beanshttps://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/mvchttps://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/context/spring-context.xsd"><!--只扫描controller注解--><context:component-scan base-package="com.mybatisStudyDay04.**.web"><context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan><!--启用MVC配置--><mvc:annotation-driven/><!--配置视图解析器--><bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/com/orderManag"/><property name="suffix" value=".jsp"/></bean></beans>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:http="http://www.springframework.org/schema/c"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beanshttps://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd"><!--配置自动化扫描机制,controlle注解不扫描--><context:component-scan base-package="com.mybatisStudyDay04.transaction"><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"><property name="driverClass" value="com.mysql.jdbc.Driver"/><property name="jdbcUrl" value="jdbc:mysql://localhost:3306/order?useUnicode=true&amp;characterEncoding=UTF-8"/><property name="user" value="root"/><property name="password" value="root"/></bean><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource"/><property name="configLocation" value="classpath:mybatis-config.xml"/></bean><!--配置数据源事务管理器--><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"/></bean><bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"><property name="transactionManager" ref="transactionManager"/><property name="transactionAttributes"><props><!--<prop key="insert*">PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED</prop>--><prop key="*">PROPAGATION_REQUIRED</prop></props></property></bean><bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"><property name="beanNames"><list><value>*ServiceImpl</value></list></property><property name="interceptorNames"><list><value>transactionInterceptor</value></list></property></bean><bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="com.mybatisStudyDay04.**.dao"/><property name="annotationClass" value="org.springframework.stereotype.Repository"/></bean>
</beans>

mybatis-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><!-- logImple属性配置指定使用LOG4J输出日志 --><settings><setting name="logImpl" value="LOG4J"/></settings><mappers><package name="com.mybatisStudyDay04.transaction.dao"/></mappers>
</configuration>

log4j.properties

#全局配置
log4j.rootLogger=info, stdout
log4j.logger.org.springframework=INFO
#控制台输出配置
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern= %d{yyyy-MM-dd HH:mm:ss} <%p> %l %m%n

SysUserController.java

@Controller
@RequestMapping("/sysUserController")
public class SysUserController {private static final Logger log = Logger.getLogger("SysUserController.class");@Autowiredprivate ISysUserService sysUserServiceImpl;@RequestMapping(value = "/updateSysUserById",method = RequestMethod.GET)public void updateSysUserById(){log.info("SysUserController updateSysUserById begin");sysUserServiceImpl.updateSysUserById();}
}

ISysUserService.java

public interface ISysUserService {void updateSysUserById();void updateTest();
}

SysUserServiceImpl.java

@Service("sysUserServiceImpl")
public class SysUserServiceImpl implements ISysUserService {private static final Logger log = Logger.getLogger("SysUserServiceImpl.class");@Autowiredprivate ISysUserDao sysUserDaoImpl;@Overridepublic void updateSysUserById(){log.info("SysUserServiceImpl updateSysUserById begin");try{SysUserVO sysUserVo1 = new SysUserVO();sysUserVo1.setId("1");sysUserVo1.setUserNum("20052301");sysUserVo1.setUserName("小王");sysUserDaoImpl.updateByPrimaryKeySelective(sysUserVo1);int i = 1/0;SysUserVO sysUserVo2 = new SysUserVO();sysUserVo2.setId("10");sysUserVo2.setUserNum("20052310");sysUserVo2.setUserName("老9");sysUserDaoImpl.updateByPrimaryKeySelective(sysUserVo2);}catch (RuntimeException e){throw new RuntimeException();}}@Overridepublic void updateTest(){log.info("SysUserServiceImpl updateSysUserById begin");try{SysUserVO sysUserVo1 = new SysUserVO();sysUserVo1.setId("1");sysUserVo1.setUserNum("20052301");sysUserVo1.setUserName("小王");sysUserDaoImpl.updateByPrimaryKeySelective(sysUserVo1);int i = 1/0;SysUserVO sysUserVo2 = new SysUserVO();sysUserVo2.setId("10");sysUserVo2.setUserNum("20052310");sysUserVo2.setUserName("老9");sysUserDaoImpl.updateByPrimaryKeySelective(sysUserVo2);}catch (RuntimeException e){throw new RuntimeException();}}}

ISysUserDao.java

@Repository("sysUserDaoImpl")
public interface ISysUserDao {int deleteUserInfo(String[] idArray);int deleteByPrimaryKey(@Param("id") String id, @Param("userNum") String userNum);int insert(SysUserVO record);int insertSelective(SysUserVO record);SysUserVO selectByPrimaryKey(@Param("id") String id);List<SysUserVO> queryUserAll();List<SysUserVO> queryUserAllOffPage(SysUserVO sysUserVO);Integer queryUserAllOffPageCount(SysUserVO sysUserVO);int updateByPrimaryKeySelective(SysUserVO record);int updateByPrimaryKey(SysUserVO record);
}

ISysUserDao.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mybatisStudyDay04.transaction.dao.ISysUserDao"><resultMap id="BaseResultMap" type="com.mybatisStudyDay04.transaction.vo.SysUserVO"><id column="ID" jdbcType="VARCHAR" property="id" /><result column="USER_NUM" jdbcType="VARCHAR" property="userNum" /><result column="USER_NAME" jdbcType="VARCHAR" property="userName" /><result column="PASSWORD" jdbcType="VARCHAR" property="password" /><result column="USER_MOTTO" jdbcType="VARCHAR" property="userMotto" /><result column="TELEPHONE" jdbcType="VARCHAR" property="telephone" /><result column="ADDRESS" jdbcType="VARCHAR" property="address" /><result column="EMAIL" jdbcType="VARCHAR" property="eMail" /><result column="ICON_NUM" jdbcType="VARCHAR" property="iconNum" /><result column="USER_SEX" jdbcType="CHAR" property="userSex" /><result column="LAST_SIGIN_TIME" jdbcType="DATE" property="lastSiginTime" /><result column="LOGIN_NUMBERS" jdbcType="INTEGER" property="loginNumbers" /><result column="CREATE_NAME" jdbcType="VARCHAR" property="createName" /><result column="CREATE_NUM" jdbcType="VARCHAR" property="createNum" /><result column="UPDATE_NAME" jdbcType="VARCHAR" property="updateName" /><result column="UPDATE_NUM" jdbcType="VARCHAR" property="updateNum" /><result column="CREAT_TIME" jdbcType="DATE" property="creatTime" /><result column="UPDATE_TIME" jdbcType="DATE" property="updateTime" /><result column="STATE" jdbcType="CHAR" property="state" /></resultMap><sql id="Base_Column_List">ID, USER_NUM, USER_NAME, PASSWORD, USER_MOTTO, TELEPHONE, ADDRESS, EMAIL, ICON_NUM,USER_SEX, LAST_SIGIN_TIME, LOGIN_NUMBERS, CREATE_NAME, CREATE_NUM, UPDATE_NAME, UPDATE_NUM,CREAT_TIME, UPDATE_TIME, STATE</sql><select id="queryUserAll" resultMap="BaseResultMap">select<include refid="Base_Column_List" />from sys_user</select><select id="queryUserAllOffPage" resultMap="BaseResultMap">selectID, USER_NUM, USER_NAME, PASSWORD, USER_MOTTO, TELEPHONE, ADDRESS, EMAIL, ICON_NUM,USER_SEX, LAST_SIGIN_TIME, LOGIN_NUMBERS, CREATE_NAME, CREATE_NUM, UPDATE_NAME, UPDATE_NUM,CREAT_TIME, UPDATE_TIME, STATEfrom sys_user<where><if test="userNum != null and userNum != ''"> and USER_NUM = #{userNum} </if><if test="userName != null and userName != ''"> and USER_NAME like concat(concat('%',#{userName}),'%')</if><if test="userSex != null and userSex != ''"> and USER_SEX = #{userSex} </if></where>limit #{startIndex},#{queryCount}</select><select id="queryUserAllOffPageCount" resultType="int">select count(id) from sys_user<where><if test="userNum != null and userNum != ''"> and USER_NUM = #{userNum} </if><if test="userName != null and userName != ''"> and USER_NAME like concat(concat('%',#{userName}),'%')</if><if test="userSex != null and userSex != ''"> and USER_SEX = #{userSex} </if></where></select><select id="selectByPrimaryKey" parameterType="map" resultMap="BaseResultMap">select<include refid="Base_Column_List" />from sys_user where ID = #{id,jdbcType=VARCHAR}</select><delete id="deleteByPrimaryKey" parameterType="map">delete from sys_userwhere ID = #{id,jdbcType=VARCHAR}and USER_NUM = #{userNum,jdbcType=VARCHAR}</delete><delete id="deleteUserInfo" parameterType="java.lang.String">delete from sys_user where id in<foreach collection="array" item="id" open="(" close=")" separator="," index="i">#{id}</foreach></delete><insert id="insert" parameterType="com.mybatisStudyDay04.transaction.vo.SysUserVO">insert into sys_user (ID, USER_NUM, USER_NAME,PASSWORD, USER_MOTTO, TELEPHONE,ADDRESS, EMAIL, ICON_NUM,USER_SEX, LAST_SIGIN_TIME, LOGIN_NUMBERS,CREATE_NAME, CREATE_NUM, UPDATE_NAME,UPDATE_NUM, CREAT_TIME, UPDATE_TIME,STATE)values (#{id,jdbcType=VARCHAR}, #{userNum,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR},#{password,jdbcType=VARCHAR}, #{userMotto,jdbcType=VARCHAR}, #{telephone,jdbcType=VARCHAR},#{address,jdbcType=VARCHAR}, #{eMail,jdbcType=VARCHAR}, #{iconNum,jdbcType=VARCHAR},#{userSex,jdbcType=CHAR}, #{lastSiginTime,jdbcType=DATE}, #{loginNumbers,jdbcType=INTEGER},#{createName,jdbcType=VARCHAR}, #{createNum,jdbcType=VARCHAR}, #{updateName,jdbcType=VARCHAR},#{updateNum,jdbcType=VARCHAR}, #{creatTime,jdbcType=DATE}, #{updateTime,jdbcType=DATE},#{state,jdbcType=CHAR})</insert><insert id="insertSelective" parameterType="com.mybatisStudyDay04.transaction.vo.SysUserVO">insert into sys_user<trim prefix="(" suffix=")" suffixOverrides=","><if test="id != null">ID,</if><if test="userNum != null">USER_NUM,</if><if test="userName != null">USER_NAME,</if><if test="password != null">PASSWORD,</if><if test="userMotto != null">USER_MOTTO,</if><if test="telephone != null">TELEPHONE,</if><if test="address != null">ADDRESS,</if><if test="eMail != null">EMAIL,</if><if test="iconNum != null">ICON_NUM,</if><if test="userSex != null">USER_SEX,</if><if test="lastSiginTime != null">LAST_SIGIN_TIME,</if><if test="loginNumbers != null">LOGIN_NUMBERS,</if><if test="createName != null">CREATE_NAME,</if><if test="createNum != null">CREATE_NUM,</if><if test="updateName != null">UPDATE_NAME,</if><if test="updateNum != null">UPDATE_NUM,</if><if test="creatTime != null">CREAT_TIME,</if><if test="updateTime != null">UPDATE_TIME,</if><if test="state != null">STATE,</if></trim><trim prefix="values (" suffix=")" suffixOverrides=","><if test="id != null">#{id,jdbcType=VARCHAR},</if><if test="userNum != null">#{userNum,jdbcType=VARCHAR},</if><if test="userName != null">#{userName,jdbcType=VARCHAR},</if><if test="password != null">#{password,jdbcType=VARCHAR},</if><if test="userMotto != null">#{userMotto,jdbcType=VARCHAR},</if><if test="telephone != null">#{telephone,jdbcType=VARCHAR},</if><if test="address != null">#{address,jdbcType=VARCHAR},</if><if test="eMail != null">#{eMail,jdbcType=VARCHAR},</if><if test="iconNum != null">#{iconNum,jdbcType=VARCHAR},</if><if test="userSex != null">#{userSex,jdbcType=CHAR},</if><if test="lastSiginTime != null">#{lastSiginTime,jdbcType=DATE},</if><if test="loginNumbers != null">#{loginNumbers,jdbcType=INTEGER},</if><if test="createName != null">#{createName,jdbcType=VARCHAR},</if><if test="createNum != null">#{createNum,jdbcType=VARCHAR},</if><if test="updateName != null">#{updateName,jdbcType=VARCHAR},</if><if test="updateNum != null">#{updateNum,jdbcType=VARCHAR},</if><if test="creatTime != null">#{creatTime,jdbcType=DATE},</if><if test="updateTime != null">#{updateTime,jdbcType=DATE},</if><if test="state != null">#{state,jdbcType=CHAR},</if></trim></insert><update id="updateByPrimaryKeySelective" parameterType="com.mybatisStudyDay04.transaction.vo.SysUserVO">update sys_user<set><if test="userName != null">USER_NAME = #{userName,jdbcType=VARCHAR},</if><if test="password != null">PASSWORD = #{password,jdbcType=VARCHAR},</if><if test="userMotto != null">USER_MOTTO = #{userMotto,jdbcType=VARCHAR},</if><if test="telephone != null">TELEPHONE = #{telephone,jdbcType=VARCHAR},</if><if test="address != null">ADDRESS = #{address,jdbcType=VARCHAR},</if><if test="eMail != null">EMAIL = #{eMail,jdbcType=VARCHAR},</if><if test="iconNum != null">ICON_NUM = #{iconNum,jdbcType=VARCHAR},</if><if test="userSex != null">USER_SEX = #{userSex,jdbcType=CHAR},</if><if test="lastSiginTime != null">LAST_SIGIN_TIME = #{lastSiginTime,jdbcType=DATE},</if><if test="loginNumbers != null">LOGIN_NUMBERS = #{loginNumbers,jdbcType=INTEGER},</if><if test="createName != null">CREATE_NAME = #{createName,jdbcType=VARCHAR},</if><if test="createNum != null">CREATE_NUM = #{createNum,jdbcType=VARCHAR},</if><if test="updateName != null">UPDATE_NAME = #{updateName,jdbcType=VARCHAR},</if><if test="updateNum != null">UPDATE_NUM = #{updateNum,jdbcType=VARCHAR},</if><if test="creatTime != null">CREAT_TIME = #{creatTime,jdbcType=DATE},</if><if test="updateTime != null">UPDATE_TIME = #{updateTime,jdbcType=DATE},</if><if test="state != null">STATE = #{state,jdbcType=CHAR},</if></set>where ID = #{id,jdbcType=VARCHAR}and USER_NUM = #{userNum,jdbcType=VARCHAR}</update><update id="updateByPrimaryKey" parameterType="com.mybatisStudyDay04.transaction.vo.SysUserVO">update sys_userset USER_NAME = #{userName,jdbcType=VARCHAR},PASSWORD = #{password,jdbcType=VARCHAR},USER_MOTTO = #{userMotto,jdbcType=VARCHAR},TELEPHONE = #{telephone,jdbcType=VARCHAR},ADDRESS = #{address,jdbcType=VARCHAR},EMAIL = #{eMail,jdbcType=VARCHAR},ICON_NUM = #{iconNum,jdbcType=VARCHAR},USER_SEX = #{userSex,jdbcType=CHAR},LAST_SIGIN_TIME = #{lastSiginTime,jdbcType=DATE},LOGIN_NUMBERS = #{loginNumbers,jdbcType=INTEGER},CREATE_NAME = #{createName,jdbcType=VARCHAR},CREATE_NUM = #{createNum,jdbcType=VARCHAR},UPDATE_NAME = #{updateName,jdbcType=VARCHAR},UPDATE_NUM = #{updateNum,jdbcType=VARCHAR},CREAT_TIME = #{creatTime,jdbcType=DATE},UPDATE_TIME = #{updateTime,jdbcType=DATE},STATE = #{state,jdbcType=CHAR}where ID = #{id,jdbcType=VARCHAR}and USER_NUM = #{userNum,jdbcType=VARCHAR}</update>
</mapper>

index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>Title</title>
</head>
<body><a href="<%=request.getContextPath()%>/sysUserController/updateSysUserById">点击</a>
</body>
</html>

pom.xml

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.suda</groupId><artifactId>mybatisStudy_Transaction01</artifactId><version>1.0-SNAPSHOT</version><packaging>war</packaging><name>mybatisStudy_Transaction01 Maven Webapp</name><!-- FIXME change it to the project's website --><url>http://www.example.com</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.7</maven.compiler.source><maven.compiler.target>1.7</maven.compiler.target><!--版本锁定--><spring.version>5.2.5.RELEASE</spring.version></properties><dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aop</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aspects</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-messaging</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-orm</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-oxm</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-expression</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-instrument</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jms</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-websocket</artifactId><version>${spring.version}</version></dependency><dependency><groupId>cglib</groupId><artifactId>cglib</artifactId><version>3.2.5</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>4.0.1</version></dependency><dependency><groupId>javax.servlet.jsp</groupId><artifactId>jsp-api</artifactId><version>2.0</version><scope>provided</scope></dependency><dependency><groupId>javax.servlet.jsp.jstl</groupId><artifactId>jstl-api</artifactId><version>1.2</version><exclusions><exclusion><artifactId>jsp-api</artifactId><groupId>javax.servlet.jsp</groupId></exclusion></exclusions></dependency><dependency><groupId>javax.servlet.jsp.jstl</groupId><artifactId>jstl-api</artifactId><version>1.2</version><exclusions><exclusion><artifactId>jsp-api</artifactId><groupId>javax.servlet.jsp</groupId></exclusion></exclusions></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>1.3.1</version></dependency><!--    <dependency>-->
<!--      <groupId>org.aspectj</groupId>-->
<!--      <artifactId>aspectjweaver</artifactId>-->
<!--      <version>1.9.2</version>-->
<!--    </dependency>--><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.4.0</version></dependency><dependency><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-core</artifactId><version>1.4.0</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.28</version></dependency><dependency><groupId>com.mchange</groupId><artifactId>c3p0</artifactId><version>0.9.5</version></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency></dependencies><build><finalName>mybatisStudy_Transaction01</finalName><pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --><plugins><plugin><artifactId>maven-clean-plugin</artifactId><version>3.1.0</version></plugin><!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --><plugin><artifactId>maven-resources-plugin</artifactId><version>3.0.2</version></plugin><plugin><artifactId>maven-compiler-plugin</artifactId><version>3.8.0</version></plugin><plugin><artifactId>maven-surefire-plugin</artifactId><version>2.22.1</version></plugin><plugin><artifactId>maven-war-plugin</artifactId><version>3.2.2</version></plugin><plugin><artifactId>maven-install-plugin</artifactId><version>2.5.2</version></plugin><plugin><artifactId>maven-deploy-plugin</artifactId><version>2.8.2</version></plugin></plugins></pluginManagement></build>
</project>

这篇关于spring中使用TransactionInterceptor拦截器和BeanNameAutoProxyCreator处理事务案例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/705852

相关文章

JVM 的类初始化机制

前言 当你在 Java 程序中new对象时,有没有考虑过 JVM 是如何把静态的字节码(byte code)转化为运行时对象的呢,这个问题看似简单,但清楚的同学相信也不会太多,这篇文章首先介绍 JVM 类初始化的机制,然后给出几个易出错的实例来分析,帮助大家更好理解这个知识点。 JVM 将字节码转化为运行时对象分为三个阶段,分别是:loading 、Linking、initialization

Spring Security 基于表达式的权限控制

前言 spring security 3.0已经可以使用spring el表达式来控制授权,允许在表达式中使用复杂的布尔逻辑来控制访问的权限。 常见的表达式 Spring Security可用表达式对象的基类是SecurityExpressionRoot。 表达式描述hasRole([role])用户拥有制定的角色时返回true (Spring security默认会带有ROLE_前缀),去

浅析Spring Security认证过程

类图 为了方便理解Spring Security认证流程,特意画了如下的类图,包含相关的核心认证类 概述 核心验证器 AuthenticationManager 该对象提供了认证方法的入口,接收一个Authentiaton对象作为参数; public interface AuthenticationManager {Authentication authenticate(Authenti

Spring Security--Architecture Overview

1 核心组件 这一节主要介绍一些在Spring Security中常见且核心的Java类,它们之间的依赖,构建起了整个框架。想要理解整个架构,最起码得对这些类眼熟。 1.1 SecurityContextHolder SecurityContextHolder用于存储安全上下文(security context)的信息。当前操作的用户是谁,该用户是否已经被认证,他拥有哪些角色权限…这些都被保

Spring Security基于数据库验证流程详解

Spring Security 校验流程图 相关解释说明(认真看哦) AbstractAuthenticationProcessingFilter 抽象类 /*** 调用 #requiresAuthentication(HttpServletRequest, HttpServletResponse) 决定是否需要进行验证操作。* 如果需要验证,则会调用 #attemptAuthentica

Spring Security 从入门到进阶系列教程

Spring Security 入门系列 《保护 Web 应用的安全》 《Spring-Security-入门(一):登录与退出》 《Spring-Security-入门(二):基于数据库验证》 《Spring-Security-入门(三):密码加密》 《Spring-Security-入门(四):自定义-Filter》 《Spring-Security-入门(五):在 Sprin

Java架构师知识体认识

源码分析 常用设计模式 Proxy代理模式Factory工厂模式Singleton单例模式Delegate委派模式Strategy策略模式Prototype原型模式Template模板模式 Spring5 beans 接口实例化代理Bean操作 Context Ioc容器设计原理及高级特性Aop设计原理Factorybean与Beanfactory Transaction 声明式事物

中文分词jieba库的使用与实景应用(一)

知识星球:https://articles.zsxq.com/id_fxvgc803qmr2.html 目录 一.定义: 精确模式(默认模式): 全模式: 搜索引擎模式: paddle 模式(基于深度学习的分词模式): 二 自定义词典 三.文本解析   调整词出现的频率 四. 关键词提取 A. 基于TF-IDF算法的关键词提取 B. 基于TextRank算法的关键词提取

Hadoop企业开发案例调优场景

需求 (1)需求:从1G数据中,统计每个单词出现次数。服务器3台,每台配置4G内存,4核CPU,4线程。 (2)需求分析: 1G / 128m = 8个MapTask;1个ReduceTask;1个mrAppMaster 平均每个节点运行10个 / 3台 ≈ 3个任务(4    3    3) HDFS参数调优 (1)修改:hadoop-env.sh export HDFS_NAMENOD

使用SecondaryNameNode恢复NameNode的数据

1)需求: NameNode进程挂了并且存储的数据也丢失了,如何恢复NameNode 此种方式恢复的数据可能存在小部分数据的丢失。 2)故障模拟 (1)kill -9 NameNode进程 [lytfly@hadoop102 current]$ kill -9 19886 (2)删除NameNode存储的数据(/opt/module/hadoop-3.1.4/data/tmp/dfs/na