Spring transaction processing mechanism, to our programming has brought great convenience, one-transaction-per-request implementation mode, is I most appreciate!
In order to implement the transaction pattern when we first started contacting spring, we typically do this when declaring a transaction.
First, declare a transaction template,
<bean id= "Txproxytemplate" abstract= "true"
class= "Org.springframework.transaction.interceptor.TransactionProxyFactoryBean" >
<property name= "TransactionManager" >
<ref bean= "TransactionManager"/>
</property>
<property name= "Transactionattributes" >
<props>
<prop key= "create*" >PROPAGATION_REQUIRED</prop>
<prop key= "delete*" >PROPAGATION_REQUIRED</prop>
<prop key= "update*" >PROPAGATION_REQUIRED</prop>
<prop key= "move*" >PROPAGATION_REQUIRED</prop>
<prop key= "save*" >PROPAGATION_REQUIRED</prop>
<prop key= "*" >PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
Next, declare a service class that uses the spring transaction template
<bean id= "UserService" parent= "Txproxytemplate" >
<property name= "Target" >
<bean class= "Com.nit.training.service.impl.UserServiceImpl" >
<property name= "Userdao" ><ref bean= "Userdao"/></property>
</bean>
</property>
</bean>
***********************
This kind of declaration way I spent two years, since the contact with Lee just now, bought in his book "Spring 2.0 Treasure", after learning, found that Spring can also be configured so
The method of transaction processing based on AOP technology, first declares a transaction interceptor
<bean id= "Transactioninterceptor"
class= "Org.springframework.transaction.interceptor.TransactionInterceptor" >
<property name= "TransactionManager" ref= "TransactionManager"/>
<property name= "Transactionattributes" >
<props>
<prop key= "create*" >PROPAGATION_REQUIRED</prop>
<prop key= "update*" >PROPAGATION_REQUIRED</prop>
<prop key= "delete*" >PROPAGATION_REQUIRED</prop>
<prop key= "save*" >PROPAGATION_REQUIRED</prop>
<prop key= "list*" >PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
Next, declare an automatic proxy
<bean class= "Org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator" >
<property name= "Beannames" >
<value>*Service</value>
</property>
<property name= "Interceptornames" >
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<bean class= "Org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor" >
<property name= "Transactioninterceptor" ref= "Transactioninterceptor"/>
</bean>
The automatic proxy means that all service-based beans are required to use the interceptor.
The following is the configuration of the Servicebean
<bean id= "UserService" class= "Com.manbu.organization.service.impl.UserServiceImpl" autowire= "ByName" >
<property name= "Userdao" ref= "Userdao"/>
</bean>
This configuration is much simpler, although for some programmers feel that the use of copy & paste, in fact, is a similar, but, configuration files can be at least more than half, easy to maintain!
Object handling mechanism configuration issues in spring