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