Currently, spring's AOP and transaction management mechanisms are rampant, and I cannot keep a little bit of relevant knowledge for future reference:
1) AOP
Org. springframework. AOP. Framework. proxyfactorybean is used most, as follows:
<Bean id = "mydao"
Class = "org. springframework. AOP. Framework. proxyfactorybean">
<Property name = "proxyinterfaces"> // proxy Interface
<Value> com. hongsoft. Test. Dao. mydao </value>
</Property>
<Property name = "target"> // proxy target
<Bean class = "com. hongsoft. Test. Dao. mydaoimpl">
<Property name = "sessionfactory">
<Ref local = "sessionfactory"> </Ref>
</Property>
</Bean>
</Property>
<Property name = "interceptornames"> // interceptor name, which can be multiple
<List>
<Value> myinterceptor </value>
</List>
</Property>
</Bean>
2) Transaction Management
Spring transaction management is an application of AOP, as follows:
<Bean id = "jdbctransactionproxy"
Class = "org. springframework. transaction. Interceptor. transactionproxyfactorybean"
Abstract = "true">
<Property name = "transactionmanager"> // Transaction Manager
<Ref bean = "jdbctransactionmanager"/>
</Property>
<Property name = "transactionattributes"> // transaction attribute
<Props>
<Prop key = "get *"> propagation_required, readonly </prop>
<Prop key = "load *"> propagation_required, readonly </prop>
<Prop key = "Modify *"> propagation_required </prop>
<Prop key = "delete *"> propagation_required </prop>
<Prop key = "add *"> propagation_required </prop>
</Props>
</Property>
</Bean>
<Bean id = "dispatch" parent = "jdbctransactionproxy">
<Property name = "target"> // target
<Bean class = "com. hongsoft. Test. Service. myserviceimpl">
<Property name = "mydao">
<Ref local = "mydao"> </Ref>
</Property>
</Bean>
</Property>
</Bean>
It can be seen that after the transaction manager and transaction attributes are specified, the interceptor method is specified in AOP.
It is very easy to use AOP for transaction processing.
3) Transaction Manager
Interface: platformtransactionmanager
Abstract class: abstractplatformtransactionmanager
Implementation class: hibernatetransactionmanager; datasourcetransactionmanager; jtatransactionmanager
Datasourcetransactionmanager is used in JDBC mode, as follows:
<Bean id = "jdbctransactionmanager" class = "org. springframework. JDBC. datasource. cetcetransactionmanager">
<Property name = "datasource"> <ref bean = "datasource"/> </property>
</Bean>