PROPAGATION_REQUIRED
2014-03-20 17:25
134 查看
原文地址:PROPAGATION_REQUIRED作者:小徐
事务传播行为种类 Spring在TransactionDefinition接口中规定了7种类型的事务传播行为,它们规定了事务方法和事务方法发生嵌套调用时事务如何进行传播: 表1事务传播行为类型
<!--Hibernate事务管理器--> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <!-- 定义事务拦截器bean--> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <!-- 事务拦截器bean需要依赖注入一个事务管理器--> <property name="transactionManager" ref="transactionManager" /> <property name="transactionAttributes"> <!-- 下面定义事务传播属性--> <props> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean id="managerTemplate" abstract="true" lazy-init="true"> <property name="teamDao"> <ref bean="teamDao" /> </property> <property name="studentDao"> <ref bean="studentDao" /> </property> </bean> <bean id ="manager" class="com.zd.service.impl.Manager" parent="managerTemplate" /> <!-- 定义BeanNameAutoProxyCreator--> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <!-- 指定对满足哪些bean name的bean自动生成业务代理 --> <property name="beanNames"> <!-- 下面是所有需要自动创建事务代理的bean--> <list> <value>manager</value> </list> <!-- 此处可增加其他需要自动创建事务代理的bean--> </property> <!-- 下面定义BeanNameAutoProxyCreator所需的事务拦截器--> <property name="interceptorNames"> <list> <!-- 此处可增加其他新的Interceptor --> <value>transactionInterceptor</value> </list> </property> </bean> <!-- 基本数据库操作 --> <bean id="baseDao" class="com.zd.service.impl.BaseDao"> <property name="hibernateTemplate"> <ref bean="hibernateTemplate"/> </property> </bean> <!-- 班级 --> <bean id="teamDao" class="com.zd.service.impl.TeamDao"> <property name="baseDao"> <ref bean="baseDao" /> </property> </bean> <!-- 学生 --> <bean id="studentDao" class="com.zd.service.impl.StudentDao"> <property name="baseDao"> <ref bean="baseDao" /> </property> </bean> public void testSaveTeam() { Team team = new Team(); team.setTeamId(DBKeyCreator.getRandomKey(12)); team.setTeamName("Class CCC"); IManager manager = (IManager) SpringContextUtil.getContext().getBean("manager"); Student student = new Student(); student.setStudentId(DBKeyCreator.getRandomKey(13)); student.setSex(Student.SEX_FEMALE); student.setStudentName("Tom"); student.setTeamId("60FHDXDIG5JQ"); manager.saveTeamAndStu(team, student); System.out.println("Save Team and Student Success"); |
相关文章推荐
- Transaction visibility / proxy / propagation REQUIRED and REQUIRES_NEW
- PROPAGATION_REQUIRED、PROPAGATION_NESTED、PROPAGATION_REQUIRES_NEW
- sp:Propagation.REQUIRED vs Propagation.REQUIRES_NEW
- Spring中 PROPAGATION_REQUIRED 解释
- spring事务 Propagation.REQUIRES_NEW、Propagation.NESTED、Propagation.REQUIRED使用时候发现的
- Spring中PROPAGATION_REQUIRED是什么意思?
- Spring中PROPAGATION_REQUIRED是什么意思?
- Spring中PROPAGATION_REQUIRED等7种事务
- Spring中PROPAGATION_REQUIRED的意思?
- Spring传播机制-Propagation.REQUIRED
- Spring中propagation="REQUIRED"意思
- dding transactional method xxxx.update' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
- 【转】Spring中 PROPAGATION_REQUIRED 解释
- PROPAGATION_REQUIRED
- 事务传播行为种类PROPAGATION_REQUIRED
- PROPAGATION_REQUIRED
- Spring中PROPAGATION_REQUIRED的意思?
- Spring7种事务传播行为类型--PROPAGATION_REQUIRED及其他6种事务传播行为种类
- spring 中事务的PROPAGATION_REQUIRED,Readonly的解释
- Spring中PROPAGATION_REQUIRED的意思