xml配置
具体代码参照上一篇Spring 整合hibernate使用Annotation进行声明式事务管理
此处省略
...
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<aop:config>
<aop:pointcut expression="execution(public * com.login.service..*.*(..))" id="bussinessService"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="add*" />
</tx:attributes>
</tx:advice>
<aop:config>...</aop:comfig>
中织入点语法,寻找具体类中使用声明式事务管理。
<aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService"/>
引入了<tx:advice>...</tx:advice>
,其中配置了需要事务管理的具体方法。
修改@Transactional的默认属性
propagation的默认值是required。
表示在执行方法一的时候存在事务,当方法一调用方法二的时候,会使用同一个事务管理。简单说就是有就使用同一个,没有就创建一个。