Spring's AOP and transaction management mechanism Overview

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.