The transaction control-related configuration in spring:
<bean id= "Txmanager" class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<property name= "DataSource" ref= "DataSource"/>
</bean>
<tx:advice id= "Txadvice" transaction-manager= "Txmanager" >
<tx:attributes>
<tx:method name= "insert*" rollback-for= "Exception"/>
<tx:method name= "update*" rollback-for= "Exception"/>
<tx:method name= "delete*" rollback-for= "Exception"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id= "dbserviceoperation" expression= "Execution (* com.htt). *service.* (..)) " />
<aop:advisor advice-ref= "Txadvice" pointcut-ref= "Dbserviceoperation"/>
</aop:config>
The rules for "expression" in the "aop:pointcut" tab are as follows:
Execution (Modifiers-pattern ret-type-pattern declaring-type-pattern? Name-pattern (Param-pattern) Throws-pattern?)
Ret-type-pattern,name-pattern (Param-pattern) is a must.
Ret-type-pattern: Identifies the return value of the method, requires the use of the full path of the class name, such as java.lang.String, or any return value for *;
Name-pattern: Specifies the method name, * represents all, such as set*, representing all methods that begin with set.
Param-pattern: Specifies the method parameter (declared type), (..) Represents all parameters, (*) represents a parameter, (*,string) represents the first parameter as any value, and the second is a String type.
An example of an expression is as follows:
Execution of any public method:
Execution (Public * * (..))
Any execution of a method that begins with "set":
Execution (* set* (..))
Execution of any method of the Accountservice interface:
Execution (* com.xyz.service.accountservice.* (..))
The execution of any method defined in the service package:
Execution (* com.xyz.service.*.* (..))
The execution of any method that defines any class in the service package and all child packages:
Execution (* com.xyz.service). *.*(..))
The execution of any method that defines the JoinPointObjP2 class in the Pointcutexp package and all the child packages:
Execution (* com.test.spring.aop.pointcutexp). joinpointobjp2.* (..)) ")
Use the | |,or representation between multiple expressions or, using the &&,and representation with,! Indicates non. For example:
<aop:config>
<aop:pointcut id= "Pointcut" expression= "(Execution (* Com.ccboy.dao). *.find* (..))) or (Execution (* Com.ccboy.dao). *.query* (..))) " />
<aop:advisor advice-ref= "Jdbcinterceptor" pointcut-ref= "Pointcut"/>
</aop:config>
Pointcut expression Expressions parsing and matching multiple conditions in Spring AOP