读书人

spring事宜配置总结

发布时间: 2012-08-28 12:37:01 作者: rapoo

spring事务配置总结
事务代理标准写法


<!--DAO层接口实现 -->
<bean id="userDAO" />
</property>
</bean>
<!--业务层接口实现,把DAO注入到Service里面 -->
<bean name="userServiceTarget" />
</property>
</bean>
<!--spring代理业务层的事务管理 -->
<bean id="userServiceProxy" />
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
<property name="target">
<ref bean="userServiceTarget" />
</property>
</bean>

事务代理简写法


<bean id="baseTxProxy" lazy-init="true"
/>
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="userDAO" />
</property>
</bean>
<bean id="userServiceProxy" parent="baseTxProxy">
<property name="target">
<bean />
</property>
</bean>
</property>
</bean>

事务自动化代理写法


<!-- 定义事务拦截器bean -->
<bean id="transactionInterceptor" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!--定义BeanNameAutoProxyCreator-->
<bean />
</property>
</bean>
<bean id="userServiceProxy" />
</property>
</bean>

转自:http://www.blogjava.net/beauty9235/archive/2008/08/18/222841.html

读书人网 >软件架构设计

热点推荐