spring配置代理事务管理配置
2015-06-08 14:11
471 查看
方式一 <!-- 用代理类对 TransactionManager进行组合切面事务管理 --> <tx:advice id="advice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="find*" propagation="REQUIRED" read-only="true" /> <tx:method name="select*" propagation="REQUIRED" read-only="true" /> <tx:method name="load*" propagation="REQUIRED" read-only="true" /> <tx:method name="get*" propagation="REQUIRED" /> <tx:method name="save*" propagation="REQUIRED" /> </tx:attributes> </tx:advice> <!-- 定义切面 --> <aop:config> <aop:pointcut expression="execution(* com.yjm.service.*.*(..))" id="point" /> <aop:advisor advice-ref="advice" pointcut-ref="point" /> </aop:config>
方式二 <!-- =========================事务管理========================= --> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager"> <ref bean="transactionManager" /> </property> <property name="transactionAttributes"> <props> <prop key="get*">PROPAGATION_REQUIRED</prop> <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="select*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="add*">PROPAGATION_REQUIRED</prop> <prop key="insert*">PROPAGATION_REQUIRED</prop> <prop key="create*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="remove*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="exit*">PROPAGATION_REQUIRED</prop> <prop key="copy*">PROPAGATION_REQUIRED</prop> <prop key="move*">PROPAGATION_REQUIRED</prop> <prop key="synch*">PROPAGATION_REQUIRED</prop> <prop key="clean*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean id="autoproxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"> <list> <value>*Service</value> </list> </property> <property name="interceptorNames"> <list> <value>transactionInterceptor</value> </list> </property> </bean>
spring 代理事务管理 都是首先封装一个事务代理类 然后 切入要使用此类规则的service类。
<!-- 声明式容器事务管理 ,transaction-manager指定事务管理器为transactionManager -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="get*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config expose-proxy="true">
<!-- 只对业务逻辑层实施事务 -->
<aop:pointcut id="txPointcut"
expression="execution(* com.sign.demo.service..*.*(..))" />
<!-- Advisor定义,切入点和通知分别为txPointcut、txAdvice -->
<aop:advisor pointcut-ref="txPointcut" advice-ref="txAdvice" />
</aop:config>
相关文章推荐
- Java自定义时间格式全接触
- Java如何调用dll
- Spring事务 REQUIRES_NEW、NESTED与NOT_SUPPORTED
- SpringMVC返回XML或者JSON格式的数据
- eclipse Maven配置及开发
- Hibernate generator小结
- Java并发编程初级-未使用Java并发包的时候
- 我的java web登录RSA加密
- Ubuntu中jdk的安装与配置
- 使用命令行执行java文件、项目(class、jar)
- SpringMVC同名参数绑定问题
- java SHA1加密算法
- 最常使用Eclipse快捷键
- 命令行中java和javac、javap使用详解(java编译命令)
- JAVA中int、String的类型转换
- 【java基础】——java基本语法(1)
- java map集合类
- java快排,找第K小的数,找前K个数
- struts2做了个简单的登录注册,jdbc链接数据库
- Android Studio中常用设置与快捷键(私人珍藏,Eclipse转AS必看)