XML, using the TX tag to configure the interceptor to implement transaction two, annotation mode
XML, using the TX tag to configure the interceptor to implement the transaction
In the main configuration is the Tx:advice and aop:config two configuration sections, which implement transaction management in the form of Spring AOP.
Tx:advice the manager that configured the transaction is TransactionManager, and Tx:method also specifies that the transaction is used if the method name matches the "add*" and "get*" methods. Propagation is the level of propagation that sets the transaction. In addition to the "add*" and "get*" methods, the transactions of the other methods are read-only (typically, you set this property to true for transactions that only execute queries, and read-only transactions fail if an update, insert, or DELETE statement occurs)
AOP:CONFIG Specifies a aop:pointcut to refer to the top advice.
This enables the transaction through an AOP interception mechanism, which does not have to be @transactional.
Second, the annotation way
In the configuration file
<!--notifications-
<!--<tx:advice id= "Txadvice" transaction-manager= "TransactionManager" >
<tx:attributes>
<! – Communication Behavior –>
<tx:method name= "delete*" propagation= "REQUIRED" read-only= "false" rollback-for= "Java.lang.Exception" No-rollback-for= "Java.lang.RuntimeException"/>
<tx:method name= "insert*" propagation= "REQUIRED" read-only= "false" rollback-for= "java.lang.RuntimeException"/ >
<tx:method name= "add*" propagation= "REQUIRED" read-only= "false" rollback-for= "Java.lang.RuntimeException"/>
<tx:method name= "create*" propagation= "REQUIRED" read-only= "false" rollback-for= "java.lang.RuntimeException"/ >
<tx:method name= "update*" propagation= "REQUIRED" read-only= "false" rollback-for= "Java.lang.Exception"/>
<tx:method name= "save*" propagation= "REQUIRED" read-only= "false" rollback-for= "Java.lang.Exception"/>
<tx:method name= "find*" propagation= "SUPPORTS" read-only= "true"/>
<tx:method name= "get*" propagation= "SUPPORTS" read-only= "true"/>
<tx:method name= "select*" propagation= "SUPPORTS" read-only= "true"/>
<tx:method name= "query*" propagation= "SUPPORTS" read-only= "true"/>
</tx:attributes>
</tx:advice>
<! – Facets –>
<aop:config>
<aop:pointcut id= "transactionpointcut" expression= "Execution (* com.xwg.service.*.* (..))"/>
<aop:advisor pointcut-ref= "Transactionpointcut" advice-ref= "Txadvice"/>
</aop:config>
This part is commented out, and then the method above adds @transactional annotations on it,
If you add this annotation to the class, it means that all of the methods under this class enable transactions
Using transactions in Java development