1.事务代理: 继承 TransactionProxyFactoryBean
<!-- 事务代理 --> <bean id="transactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true"> <property name="transactionManager"> <ref bean="transactionManager" /> </property> <property name="transactionAttributes"> <props> <prop key="select*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- TransactionManager定义。 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- MyBatis transactionTemplate --> <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate"> <property name="transactionManager" ref="transactionManager" /> </bean> <!-- MyBatis sqlSessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:mybatis.xml" /> <property name="mapperLocations"> <list> <value>classpath:com/desk/user/core/dao/**/*Mapper.xml </value> </list> </property> </bean> <!-- MyBatis sqlSessionTemplate --> <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg ref="sqlSessionFactory" /> </bean>
业务处理bean 注入方式
<bean id="userService" parent="transactionProxy"> <property name="target"> <bean class="com.desk.user.core.service.user.UserServiceImpl" /> </property> </bean>
2.事物代理:BeanNameAutoProxyCreator beanName 代理
<!--事务拦截器 --> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager" ref="transactionManager" /> <property name="transactionAttributes"> <props> <prop key="select">PROPAGATION_REQUIRED,readOnly</prop> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="proxyTargetClass"> <value>true</value> </property> <property name="beanNames"> <list> <value>*ServiceImpl</value> </list> </property> <property name="interceptorNames"> <list> <value>transactionInterceptor</value> </list> </property> </bean> <!--异常和超时拦截器 --> <bean id="exceptionHandler" class="com.desk.common.handler.ExceptionHandler" /> <bean id="timeHandler" class="com.desk.common.handler.TimeHandler" /> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="proxyTargetClass"> <value>true</value> </property> <property name="beanNames"> <list> <!-- <value>*Render</value> <value>*Controller</value> <value>*BOImpl</value> --> <value>*ServiceImpl</value> <value>*DAOImpl</value> </list> </property> <property name="interceptorNames"> <list> <value>exceptionHandler</value> <value>timeHandler</value> </list> </property> </bean> <!-- TransactionManager定义。 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- MyBatis transactionTemplate --> <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate"> <property name="transactionManager" ref="transactionManager" /> </bean> <!-- MyBatis sqlSessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:mybatis.xml" /> <property name="mapperLocations"> <list> <value>classpath:com/desksoft/oceanus/user/core/dao/**/*Mapper.xml </value> </list> </property> </bean> <!-- MyBatis sqlSessionTemplate --> <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg ref="sqlSessionFactory" /> </bean>
业务处理bean注入
<!-- service 注入 --> <bean id="userService" class="com.desksoft.oceanus.user.core.service.user.UserServiceImpl" />
相关推荐
aop与spring事务处理
Spring事务管理4种方式 入门级 最简单demo PlatformTransactionManager TransactionTemplate
spring 事务处理
事务简介 二、程序举例环境搭建 o1. 创建数据表 ...三、使用 Spring 的事务注解管理事务 o1. 声明事务管理器 o2. 开启注解驱动 o3. 完整Spring配置文件 o4. 业务层 public 方法加入事务属性 o5. 测试
spring整合hibernate实现事务处理 1.spring整合hibernate实现事务处理-注解方式 2.spring整合hibernate实现事务处理-XML方式
Spring Hibernate 事务处理 详细说明 Spring Hibernate 事务处理 详细说明
这是在java里使用到spring的配置文件里,添加事务处理过程,以至于可以回滚事务,当中使用到拦截器。
spring声明式事务处理demo。myeclipse工程
主要介绍了Spring事务处理原理步骤详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
spring-tx spring-transaction spring事务管理实例
使用Spring Cloud微服务架构 阿里巴巴开源Seate处理分布式程序事务一致性问题demo 使用IDEA开发
NULL 博文链接:https://todd-liangt.iteye.com/blog/337274
Spring源代码解析(六):Spring声明式事务处理.doc
NULL 博文链接:https://yizhenn.iteye.com/blog/2293339
Spring延迟加载和声明式事务处理最终解决方案(修正版)
NULL 博文链接:https://babalaaaa.iteye.com/blog/538687
Spring 1_2的hibernate事务处理,更加详细的说明事务的处理在SPRING中
spring事务处理,整理的。希望对朋友们有帮助
spring boot 纯注解方法事务控制回滚,注解+简单配置文件使用多线程demo
一个完整的s2sm整合项目,含jar包。使用注释型事务管理。给大家参考了。