Spring transaction based on XML configuration method

Source: Internet
Author: User

Refer to the previous declarative transaction example: http://www.cnblogs.com/caoyc/p/5632198.html

We have made the corresponding changes. In DAO and in each class in the service, remove all annotation labels. Then provide a setxxx () method for each field

Finally, configure the Applicationcontext.xml file. The contents are as follows:

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Beansxmlns= "Http://www.springframework.org/schema/beans"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4 XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"5 Xmlns:context= "Http://www.springframework.org/schema/context"6 Xmlns:tx= "Http://www.springframework.org/schema/tx"7 xsi:schemalocation= "Http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd 8 Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 9 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsdTen Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-4.3.xsd "> One  A  -     <!--Read Db.properties configuration information - -     <Context:property-placeholder Location= "Classpath:db.properties"/> the      -     <!--Configuring a C3P0 data source - -     <BeanID= "DataSource"class= "Com.mchange.v2.c3p0.ComboPooledDataSource"> -         < Propertyname= "User"value= "${jdbc.user}"/> +         < Propertyname= "Password"value= "${jdbc.password}"/> -         < Propertyname= "Driverclass"value= "${jdbc.driverclass}"/> +         < Propertyname= "Jdbcurl"value= "${jdbc.jdbcurl}"/> A     </Bean> at      -     <!--Configure a JdbcTemplate to manipulate the database - -     <BeanID= "JdbcTemplate"class= "Org.springframework.jdbc.core.JdbcTemplate"> -         < Propertyname= "DataSource"ref= "DataSource"/> -     </Bean> -      in     <!--Configure DAO - -     <BeanID= "Bookdao"class= "Com.proc.dao.BookDao"> to         < Propertyname= "JdbcTemplate"ref= "JdbcTemplate"/> +     </Bean> -     <BeanID= "Storedao"class= "Com.proc.dao.StoreDao"> the         < Propertyname= "JdbcTemplate"ref= "JdbcTemplate"/> *     </Bean> $     <BeanID= "Userdao"class= "Com.proc.dao.UserDao">Panax Notoginseng         < Propertyname= "JdbcTemplate"ref= "JdbcTemplate"/> -     </Bean> the      +     <!--Configure Service - A     <BeanID= "Bookshopservice"class= "Com.proc.service.BookShopServiceJdbcImps"> the         < Propertyname= "Bookdao"ref= "Bookdao"/> +         < Propertyname= "Storedao"ref= "Storedao"/> -         < Propertyname= "Userdao"ref= "Userdao"/> $     </Bean> $      -     <!--Configure transaction manager - -     <BeanID= "TransactionManager"class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager"> the         < Propertyname= "DataSource"ref= "DataSource"></ Property> -     </Bean>Wuyi  the     <!--Configure transaction Properties - -     <Tx:adviceID= "Advice"> Wu         <tx:attributes> -             <Tx:methodname= "get*"read-only= "true"/> About             <Tx:methodname= "find*"read-only= "true"/> $             <Tx:methodname="*"/> -         </tx:attributes> -     </Tx:advice> -      A     <!--to configure a transaction entry point: AOP cut-in - +     <Aop:config> the         <!--configuring a cut-in expression - -         <Aop:pointcutexpression= "Execution (* com.proc.service.*.* (..))"ID= "Pointcut"/> $         <Aop:advisorPointcut-ref= "Pointcut"Advice-ref= "Advice"></Aop:advisor> the     </Aop:config> the </Beans>

This way, the XML-based transactions are well-configured.

Code Analysis:

Transactions take the form of AOP. So you need to configure an AOP pointcut. Specify which classes and methods to adopt for transactions

Spring-based transactions with XML configuration

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.