spring管理hibernate事务配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <!-- spring配置hibernate的事务管理器 职责:完成session的开启和关闭,完成事务的开启提交回滚 --> <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <!-- 配置事务的传播特性 需要配置:transaction-manager事务管理器,id="txAdvice"传播特性的id,<tx:method --> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <!--为每个操作指定指定事务传播特性--> <tx:method name="add*" propagation="REQUIRED"/> <tx:method name="del*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="*" read-only="true"/> </tx:attributes> </tx:advice> <!-- 配置事务的管理位置(aop:pointcut),*表示管理的范围分别表示:所有文件,类,方法,参数 --> <aop:config> <aop:pointcut id="servicePointCut" expression="execution(* com.ru.service.impls.*.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="servicePointCut"/> </aop:config> <!-- 启用事务注解 如果service中使用了事务,需要@Transactional--> <tx:annotation-driven transaction-manager="txManager"/> <bean id="myProductService" class="product.SimpleProductService"> <property name="productDao" ref="myProductDao"/> </bean> </beans>
相关推荐
牧场SZShepherd 2020-07-19
vivenwan 2019-12-17
heniancheng 2020-07-26
qingjiuquan 2020-07-18
幸运小侯子 2020-06-21
hxw0 2020-06-16
airfling 2020-06-08
咻pur慢 2020-06-08
shuiluobu 2020-06-03
melonjj 2020-05-31
neweastsun 2020-05-27
shuiluobu 2020-05-12
whbing 2020-04-30
KFLING 2020-04-26
happinessaflower 2020-04-19