Spring claims-based transaction management approach

Source: Internet
Author: User

Annotation-based transaction management It makes it easy to manage transactions but you still need to use the @transactional annotation tag for all the implementation classes of the business layer, so is there a simpler way to manage transactions with barely?

Claims-based transaction management requires only a small amount of configuration to add transaction management for all business layer logic, removing Userserviceimpl.java @ on a springmvc+hibernate4+bootstrap3 basis transactional annotations and modify the Applicationcontext.xml as follows:

<?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 " xmlns:context=" Http://www.springframework.org/schema/context "xsi:schemalocation=" http://www.springframework.org/schema/ beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd    http:// www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.0.xsdhttp:// www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http:// www.springframework.org/schema/context   http://www.springframework.org/schema/context/ Spring-context-3.0.xsd "><context:property-placeholder location=" Classpath:db_info.properties "/> <aop:aspectj-autoproxy/><!--  Only scanned by @service  @Repository annotation Tag class  --><context:component-scan base-package= "Com.zws"  use-default-filters= "false" >  <context:include-filter type= "Annotation"  expression= " Org.springframework.stereotype.Repository " />     <context:include-filter  type= "Annotation"  expression= "Org.springframework.stereotype.Service"  /> </context: Component-scan><bean id= "DataSource"  class= "Com.mchange.v2.c3p0.ComboPooledDataSource"   Destroy-method= "Close" ><property name= "Driverclass"  value= "${jdbc.driverclassname}" ></ Property><property name= "Jdbcurl"  value= "${jdbc.url}" ></property><property  Name= "User"  value= "${jdbc.username}" ></property><property name= "password"  value= "${ Jdbc.password} "></property><property name=" Checkouttimeout " value=" ></ Property><property name= "Acquireincrement" &Nbsp;value= "3" ></property><property name= "MaxIdleTime"  value= "></property>" <property name= "Maxpoolsize"  value= "></property></bean> <bean id=" Sessionfactory " class=" Org.springframework.orm.hibernate4.LocalSessionFactoryBean ">     <property name= "DataSource"  ref= "DataSource" ></property><property name= " Hibernateproperties "><props>                 <prop key= "Hibernate.dialect" >org.hibernate.dialect.mysqldialect</prop >                   <prop key= "Hibernate.show_sql" >true</prop>                   <prop key= "Hibernate.format_sql" > True</prop> &nBsp;                <prop  key= "Hibernate.hbm2ddl.auto" >update</prop>  </props></property>< Property name= "Packagestoscan" ><list><value>com.zws.user.beans</value></list> </property></bean><bean id= "TransactionManager"  class= " Org.springframework.orm.hibernate4.HibernateTransactionManager "><property name=" Sessionfactory "  ref= "Sessionfactory"  /></bean><!----><!--     declarative container transaction management   Transaction-manager specifies that the transaction manager is Transactionmanager  -->    <tx:advice id= " Txadvice " transaction-manager=" TransactionManager ">         <tx:attributes>            <tx:method  name= "add*"  propagation= "REQUIRED"  />&nbsP;           <tx:method name= "get*"   propagation= "REQUIRED"  />            < Tx:method name= "query*"  propagation= "REQUIRED"  read-only= "true"  />             <tx:method name= "*"  read-only= "true"  / &GT;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&LT;/TX:ATTRIBUTES&GT;&NBSP;&NBSP;&NBSP;&NBSP;&LT;/TX: advice>        <!--  Implement transactions only for the business logic layer-->     <aop:config>        <aop:pointcut id= "TxPointcut"  expression= "Execution (*&NBSP;COM.ZWS. Service.impl.*.* (..)) "  />        <aop:advisor pointcut-ref= "TxPointcut"  advice-ref= "Txadvice"/>    </aop:config></beans> 

Tx:advice is used to define an enhancement, where the enhancement is transaction management, Aop:pointcut is used to define the tangency point, and the aop:advisor tag adds transaction management enhancements to the specified tangency point for the purpose of enhancing the pointcut.

This article is from the "Evan" blog, be sure to keep this source http://wenshengzhu.blog.51cto.com/5151285/1701023

Spring claims-based transaction management approach

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.