首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

spring配备事物的几种方法

2012-11-11 
spring配置事物的几种方法方法一:----------------------------------------------bean nametransactio

spring配置事物的几种方法
方法一:----------------------------------------------<bean name="transactionManager" /> </property></bean><bean name="transactionProxyTemplate" abstract="true" /> </property><property name="target"> <list> <ref bean="classService" /><!-- 要配置事物的Service或者DAO都配置到这里就OK了 --> <ref bean="userService" /> </list> </property> <property name="transactionAttributes"> <props> <prop key="find*">PROPAGATION_REQUIRED, readOnly</prop> <prop key="create*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="modify*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property></bean>第二种方法:----------------------------------------------<bean name="transactionManager" /> </property></bean><bean name="transactionProxyTemplate" abstract="true" /> </property> <property name="transactionAttributes"> <props> <prop key="find*">PROPAGATION_REQUIRED, readOnly</prop> <prop key="create*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="modify*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property></bean><bean name="classService" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default" parent="transactionProxyTemplate"><!-- 哪个Service需要事物就配一个这样的Bean --> <property name="target"> <bean /> </property> </bean> </property></bean>方法三:----------------------------------------------为每一个需要事物的DAO配置一个代理Bean<bean id="deptsortDAOProxy" /> </property> <property name="target"> <ref bean="deptsortDAO" /> </property> <property name="transactionAttributes"> <props> <prop key="create*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property></bean>Service配置的时候直接引用配置好的代理DAO<bean id="deptsortService" /> </property></bean>

?

热点排行