Two policies for spring declarative transaction configuration SPRINGAOP and Agent Beannameautoproxycreator for the Bean post processor

Source: Internet
Author: User

There are two types of transaction configurations in spring: 1 programmatic Transaction Management configuration, 2 declarative transaction management configuration. The configuration of the two declarative transactions is described below, with declarative transactions being less coupled than programming transaction code, and unordered writing of any transaction-managed first-pass code. The two declarative transaction configuration policies are: SPRINGAOP transaction management and agent Beannameautoproxycreator management transactions for the Bean post processor.

1, SPRINGAOP Transaction Management configuration 1.1, configuration data Source:

     <bean id= "Pycdatasource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method= "Close" >< Property Name= "Driverclass" value= "${pyc.jdbc.driver}"/><property name= "Jdbcurl" value= "${pyc.jdbc.url}"/ ><property name= "user" value= "${pyc.jdbc.user}"/><property name= "password" value= "${pyc.jdbc.password} "/><property name=" Checkouttimeout "value=" 30000 "/><property name=" Idleconnectiontestperiod "value=" 30 "/><property name=" MaxIdleTime "value=" "/><property name=" Initialpoolsize "value=" 5 "/>< Property Name= "Minpoolsize" value= "5"/><property name= "maxpoolsize" value= "/><property name=" Acquireincrement "value=" 5 "/></bean>

1.2. Configure the transaction manager

       <!--configuration transaction manager--><bean id= "TransactionManager" class= " Org.springframework.jdbc.datasource.DataSourceTransactionManager "><property name=" datasource "ref=" DataSource "/></bean>

1.3. Configuring Transaction enhancement Processing Beans

Spring provides the TX configuration transaction Management,<tx:advice.../> element to configure Transaction enhancement processing, using <aop:advisor.../> enabling proxies.

     <!--configuring transaction enhancement processing beans, specifying transaction manager--><tx:advice id= "Transactionadvice" transaction-manager= "TransactionManager" >    <!--configuring verbose transaction processing Semantics--><tx:attributes><tx:method name= "insert*" propagation= "REQUIRED"/> <tx:method name= "update*" propagation= "REQUIRED"/><tx:method name= "delete*" propagation= "REQUIRED"/> <tx:method name= "get*" propagation= "SUPPORTS" read-only= "true"/><tx:method name= "find*" propagation= " SUPPORTS "read-only=" true "/><tx:method name=" select* "propagation=" SUPPORTS "read-only=" true "/><!-- The other uses the default transaction mode--><tx:method name= "*"/></tx:attributes></tx:advice>

1.4. AOP Agent

   <!--Spring AOP transaction Management--><aop:config>    <!--configuration pointcut--><aop:pointcut id= "Transactionpointcut" expression= "Execution (* org.andy.shop.service). *impl.* (..)) " /><!--Specifies to apply txadvice transaction enhancement processing--><aop:advisor pointcut-ref= "Transactionpointcut" advice-ref= "in a txadvice pointcut Transactionadvice "/></aop:config>

2, Beannameautoproxycreator automatically create the transaction agent

The configuration of the data source, the configuration of the transaction manager, and the same as above are omitted here ....

2.3. Transaction blocker

    <!--declarative transactions, transaction interceptors--><bean id= "Transactioninterceptor" class= " Org.springframework.transaction.interceptor.TransactionInterceptor "><property name=" TransactionManager " ref= "TransactionManager"/><!--Configure transaction Properties--><property name= "Transactionattributes" ><!--define transaction propagation Properties- -><props><prop key= "get*" >propagation_required,readonly</prop><prop key= "find*" > Propagation_required,readonly</prop><prop key= "*" >PROPAGATION_REQUIRED</prop></props> </property></bean>

2.4. Define Beannameautoproxycreator

Beannameautoproxycreator, the Bean is a post-bean processor that does not have to be referenced, so there is no id attribute for the bean post-processor, which automatically creates the transaction agent for the target bean based on the transaction interceptor. Beannameautoproxycreator is a proxy creator that generates an automatic proxy based on the bean name, which typically takes two parameters. The first is the Beannames property, which is used to set which beans need to be automatically generated by a proxy. Another property is Interceptornames, which specifies the transaction interceptor, and when the transaction proxy is created automatically, the corresponding transaction proxy is generated based on the properties of these transaction interceptors.

<!--Bean Post processor beannameautoproxycreator, create a transaction agent--><beanclass= according to the list configuration " Org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator "><!--here are all the beans that need to automatically create the transaction broker-->< Property Name= "Beannames" ><list><value>*ServiceImpl</value></list></property> <!--The following defines the transaction interceptors required for Beannameautoproxycreator--><property name= "Interceptornames" ><list><value >transactionInterceptor</value></list></property></bean>

Blog Source : Http://blog.csdn.net/fengshizty




Two policies for spring declarative transaction configuration SPRINGAOP and Agent Beannameautoproxycreator for the Bean post processor

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.