Spring4 declarative Transaction -02 XML configuration method

Source: Internet
Author: User

1. Configure common Controller,service, DAO beans.

<!--Configure DAO, service -    <BeanID= "Bookshopdao"class= "Com.liujl.spring.tx.xml.BookShopDaoImpl">        < Propertyname= "JdbcTemplate"ref= "JdbcTemplate"></ Property>    </Bean>        <BeanID= "Bookshopservice"class= "Com.liujl.spring.tx.xml.serivice.impl.BookShopServiceImpl">        < Propertyname= "Bookshopdao"ref= "Bookshopdao"></ Property>    </Bean>        <BeanID= "Cashier"class= "Com.liujl.spring.tx.xml.serivice.impl.CashierImpl">        < Propertyname= "Bookshopservice"ref= "Bookshopservice"></ Property>    </Bean>

2. Configure the transaction manager bean

<!--configuration transaction manager hibernate, JPA are similar to this -    <BeanID= "TransactionManager"class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager">        < Propertyname= "DataSource"ref= "DataSource"></ Property>    </Bean>

3. Introduction of the TX namespace

xmlns:tx= "Http://www.springframework.org/schema/tx"

4. Configure the transaction properties (the method name can use wildcard characters *)

<!--Configure transaction Properties -    <Tx:adviceID= "Txadvice"Transaction-manager= "TransactionManager">        <tx:attributes>            <Tx:methodname= "Purchase"Propagation= "REQUIRED"/>            <Tx:methodname= "Checkout"Propagation= "REQUIRED"/>            <Tx:methodname= "get*"read-only= "true"/>                        <Tx:methodname= "find*"read-only= "true"/>                    </tx:attributes>    </Tx:advice>

5. Introduction of the AOP namespace

xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"

6. Configure the tangency point of the transaction and associate the transaction pointcut with the transaction properties

<!--configures the tangency point of a transaction and does not correlate transaction pointcuts with transaction properties -    <Aop:config>        <Aop:pointcutexpression= "Execution (* com.liujl.spring.tx.xml.serivice.*.* (..))"ID= "Txpointcut"/>        <Aop:advisorAdvice-ref= "Txadvice"Pointcut-ref= "Txpointcut"/>    </Aop:config>
Properties of the transaction:  
    Propagation Declares the propagation property of a transaction by default, REQUIRED, which is included in the transaction above, discarding itself to handle the transaction    Requires_new This method as the execution unit, opening a new transaction ( External transactions are suspended before and after method execution)        isolation Specifies the isolation level of the transaction, the most commonly used value is read_committed read and submit
    3. By default, spring's declarative transactions are rolled back as long as all runtimes .    norollbackfor Specifies the exception that does not roll back, other similar
    readOnly Specifies whether a transaction is read- only , which means that the transaction reads only the data but does not update the data, which    helps the database engine to optimize the transaction. If it is really a read-only database worthwhile method, you should set Readonly=true    
    Timeout Specifies the amount of time a transaction can occupy before forcing a rollback

Spring4 declarative Transaction -02 XML configuration method

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.