Spring1.0 standard transaction Configuration
Define a basetxservice for basic transaction definition. The type is transactionproxyfactorybean. If the service is not based on an interface, use cgilib to implement AOP and define <property name = "proxytargetclass" value = "true"/>
The actual manager class is set to parent = basetxservice, and the target is an anonymous actual manager class. To define special transactions, use the merge = true attribute to define new transactions on the transactionattributes node of the manager.
<Bean id = "basetxservice" class = "org. springframework. transaction. Interceptor. transactionproxyfactorybean"
Abstract = "true">
<Property name = "transactionmanager" ref = "transactionmanager"/>
<Property name = "proxytargetclass" value = "true"/>
<Property name = "transactionattributes">
<Props>
<Prop key = "get *"> propagation_required, readonly </prop>
<Prop key = "find *"> propagation_required, readonly </prop>
<Prop key = "Save *"> propagation_required </prop>
<Prop key = "Remove *"> propagation_required </prop>
</Props>
</Property>
<Property name = "preinterceptors">
<List>
<Ref bean = "methodsecurityinterceptor"/>
</List>
</Property>
</Bean> <bean id = "bookmanager" parent = "basetxservice">
<Property name = "target">
<Bean class = "org. springside. Bookstore. admin. Manager. bookmanager"/>
</Property>
</Bean> Spring 2 New configuration of. 0:
If the service is not based on an interface, use cgilib to implement AOP and define proxy-target-class = "true"
<AOP: config proxy-target-class = "true">
<AOP: Advisor pointcut = "execution (* COM. XYZ. Service... * manager. * (...)" advice-ref = "txadvice"/>
<AOP: Advisor pointcut = "execution (* COM. XYZ. Service... * manager. Save (...)" advice-ref = "fooadvice"/>
</AOP: config> <TX: Advice id = "txadvice" transaction-Manager = "transactionmanager">
<TX: Attributes>
<TX: method name = "get *" Read-Only = "true"/>
<TX: method name = "find *" Read-Only = "true"/>
<TX: method name = "*"/>
</TX: Attributes>
</TX: Advice>
<Bean id = "bookmanager" class = "org. springside. Bookstore. commons. Service. bookmanager"/> where com. XYZ is the prefix of your project package.
2. Progress
1. The configuration method of AOP is also AOP.
Compare the configuration file of 1.0, because the following2The mentioned restrictions are related to the security acegi methodsecurityinterceptor interceptor which should be configured in the preinterceptors attribute of transactionproxyfactorybean about the transaction. In this way, no AOP is needed.
While2. 0 uses ponintcut expression, so it is very AOP to configure all aspect.
2In. 1.0, an object that has already been AOP cannot be reused by AOP.
InSpringRod said in the 1.0 document that, for example, <bean id = "bookmanager" parent = "basetxservice"> has performed AOP once. If you want to configure another AOP layer on this bean, for example, to cache the method execution result2The. 0 method is defined. The cglib method reports an error, but the interface-based method does not have any results.
3. bookmanager can define itself directly, rather than making an anonymous internal target like 1.0.
Although beannameautoproxycreator in the 1.0 era has a similar effect, it is dangerous to use beanname for Fuzzy Matching. The pointcut Syntax of aspectj is not detailed.
3. Syntax
Translated by manjianghongSpringReference document 6.3 Schema-based AOP support provides explanations for three assembly methods: aspect, Advisor, and advide. Among them, aspect is an original method of aspectj, but it is a little complicated.
The only thing that is hard to understand is the syntax in pointcut. In fact, it is also very easy to learn,SpringReference document 6.2. 3.4 complete descriptions are provided in the example. In fact, a row of sub-databases used to be
Execution (modifiers-pattern? Ret-type-pattern declaring-type-pattern? Name-pattern (param-pattern) throws-pattern ?) Where are the modifiers-pattern with question marks? (Public/protected) and declaring-type-pattern? Throws-pattern? Optional
Explanation of execution (**. bookmanager. Save:
The first * indicates that the returned value of ret-type-pattern can be arbitrary,
*. Bookmanager represents the bookmanager class in any pacakge.
If it is written as com. XYZ. Service. *, it indicates any class under com. XYZ. Service.
Com. XYZ. Service... * COM. XYZ. Service represents any class in COM. XYZ. Service and its sub-package.
"Save" indicates the Save method, or "Save *" indicates the savebook () method.
(..) Matches zero or multiple parameters, any type
(X,...) The type of the first parameter must be X
(X, S,...) matches at least four parameters. The first parameter must be of the X type, the second and third parameters can be arbitrary, and the fourth parameter must be of the S type.
Note:
1. Do not write name-pattern as * .. * manager, so that managers of all third-party class libraries suchSpringPlatformtranstationmanager is also added to AOP, which is very dangerous. So it is best to add the project package prefix, such as "org. springside... * manager"
2. Because of the existence of *, all methods will be modified. Some of the final methods of hibernatetemplate cannot be modified by cglib, and they will be thrown to warning, which is harmless.
4. Transaction definition options
generally, the default propagation_required can be used as the transaction definition. Other options are rarely used. It is worth noting that a propagation_nested embedded transaction is a multi-level transaction. If an error occurs, only the rollback sub-transaction itself does not roll back all the operations of the master transaction. For example, the shiporder function of ordermanager calls the SAVE Function. If SAVE () is defined as an embedded transaction, it stores the save point when it enters save. If an error occurs in SAVE, it will be rolled back to the Save point, but other operations will not be affected. This requires support for the jdbc3.0 savepoint function. In general, when services are embedded into each other for calling, if all services are defined as propagation_required, one of the operations fails and all rollback operations are performed.