Spring Transaction Processing

Source: Internet
Author: User

Spring performs transaction rollback by default: Transaction rollback is initiated only when there is no processing of exceptions to the operations of the database in the class on which the transaction is opened.

And many times the business needs to handle the thrown exception, so if try,catch the way to operate the database, the transaction will not be actively rolled back, then need to manually go to the transaction rollback

Transactionaspectsupport.currenttransactionstatus (). setrollbackonly ();//manual rollback for caught exceptions

Spring AOP configuration file, you need to configure the classes in <list> to turn on transactions

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:p= "http://www.springframework.org/schema/p"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">    <Beanclass= "Org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">        < Propertyname= "Beannames">            <List>                <IDREFBean= "Baseservice" />                <IDREFBean= "Asyncserviceimpl" />                <IDREFBean= "Transactionservice" />                <IDREFBean= "Yhxxzhcxservice" />            </List>        </ Property>        < Propertyname= "Interceptornames">            <List>                <IDREFBean= "Transactioninterceptor" />            </List>        </ Property>    </Bean>    <BeanID= "Transactioninterceptor"class= "Org.springframework.transaction.interceptor.TransactionInterceptor">        < Propertyname= "TransactionManager"ref= "TransactionManager" />        < Propertyname= "Transactionattributes">            <Props>                <propKey= "get*">Propagation_supports,-exception,readonly</prop>                <propKey= "find*">Propagation_supports,-exception,readonly</prop>                <propKey= "search*">Propagation_supports,-exception,readonly</prop>                <propKey= "query*">Propagation_supports,-exception,readonly</prop>                <propKey= "count*">Propagation_supports,-exception,readonly</prop>                <propKey="*">Propagation_required,-exception</prop>            </Props>        </ Property>    </Bean>    <BeanID= "TransactionManager"class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager">        < Propertyname= "DataSource"ref= "DataSource" />    </Bean></Beans>

Spring Transaction Processing

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.