Two ways to handle spring transactions.

Source: Internet
Author: User
Tags aop config

Spring Transaction Management:
This can be done in two ways:

One is to use AOP to control transactions:
<!--configuration Transaction Manager-
<bean id= "TransactionManager" class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name= "Sessionfactory" >
<ref local= "Sessionfactory"/>
</property>
</bean>

<!--configuring transaction Features--
<tx:advice id= "Txadvice" transaction-manager= "TransactionManager" >
<tx:attributes>
<tx:method name= "*" propagation= "REQUIRED"/>
<!--
<tx:method name= "add*" propagation= "REQUIRED"/>
<tx:method name= "del*" propagation= "REQUIRED"/>
<tx:method name= "update*" propagation= "REQUIRED"/>
<tx:method name= "deploy*" propagation= "REQUIRED"/>
<tx:method name= "submit*" propagation= "REQUIRED"/>
<tx:method name= "*" read-only= "true"/>
-
</tx:attributes>
</tx:advice>

<!--What classes of methods are configured for transaction management--
<aop:config>
<aop:pointcut id= "Allmanagermethod" expression= "Execution (* com.bjsxt.oa.managers.*.* (..))" />
<aop:advisor advice-ref= "Txadvice" pointcut-ref= "Allmanagermethod"/>
</aop:config>

Two is to control transactions by means of a transaction interceptor:
<!--Transaction Manager for a single Hibernate sessionfactory (alternative to JTA)-- <bean id= "Mytransactionmanager" class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name= "Sessionfactory" >
<ref local= "mysessionfactory"/>
</property>
< /bean>
<!--configuration Transaction Management-
<bean id= "UserService" class= " Org.springframework.transaction.interceptor.TransactionProxyFactoryBean ">
<property name=" TransactionManager ">
<ref local=" Mytransactionmanager "/>
</property>
<property name=" Target ">
<ref local=" Logintarget "/>
</property>
<property name=" transactionattributes >
<props>
<prop key= "save*" >PROPAGATION_REQUIRED</prop>
</props>
</ Property>
</bean>

<!--Ordertarget Primary business object implementation--
<bean id= "Logintarget" class= "Com.test.spring.UserServiceImpl" >
<property name= "Userdaoif" >
<ref local= "Userdao"/>
</property>
</bean>

<!--DAO Object:hibernate implementation--
<bean id= "Userdao" class= "Com.test.hibernate.UserDAOImpl" >
<property name= "Sessionfactory" >
<ref local= "Mysessionfactory"/>
</property>
</bean>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.