Spring XML configuration-based transactions (14)

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"3Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4Xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"5Xmlns:context= "Http://www.springframework.org/schema/context"6Xmlns:tx= "Http://www.springframework.org/schema/tx"7Xsi:schemalocation= "Http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd8Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd9Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd10Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd ">111213<!--Read Db.properties configuration information-14<Context:property-placeholderLocation= "Classpath:db.properties"/>1516<!--Configuring a C3P0 data source-17<BeanId= "DataSource"Class= "Com.mchange.v2.c3p0.ComboPooledDataSource">18<PropertyName= "User"Value= "${jdbc.user}"/>19<PropertyName= "Password"Value= "${jdbc.password}"/>20<PropertyName= "Driverclass"Value= "${jdbc.driverclass}"/>21st<PropertyName= "Jdbcurl"Value= "${jdbc.jdbcurl}"/>22</Bean>2324<!--Configure a JdbcTemplate to manipulate the database-25<BeanId= "JdbcTemplate"Class= "Org.springframework.jdbc.core.JdbcTemplate">26<PropertyName= "DataSource"Ref= "DataSource"/>27</Bean>2829<!--Configure DAO-30<BeanId= "Bookdao"Class= "Com.proc.dao.BookDao">31<PropertyName= "JdbcTemplate"Ref= "JdbcTemplate"/>32</Bean>33<BeanId= "Storedao"Class= "Com.proc.dao.StoreDao">34<PropertyName= "JdbcTemplate"Ref= "JdbcTemplate"/>35</Bean>36<BeanId= "Userdao"Class= "Com.proc.dao.UserDao">37<PropertyName= "JdbcTemplate"Ref= "JdbcTemplate"/>38</Bean>3940<!--Configure Service-41<BeanId= "Bookshopservice"Class= "Com.proc.service.BookShopServiceJdbcImps">42<property name= "Bookdao" ref= "Bookdao"/>43 <property name= "Storedao" ref= " Storedao "/>44 <property name=" Userdao "ref=" Userdao "/>45 </bean>46 <!--configuration transaction manager-->48 <bean Id= "TransactionManager" class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" >49 < Property Name= "DataSource" ref= "DataSource" ></property>50 </bean>51 <!--Configure transaction properties-->53 <TX: Advice id= "Advice" >54 <tx:attributes>55 <tx:method name= "get*" read-only= "true"/>56 <tx:method name = "find*" read-only= "true"/>57 <tx:method name= "*"/>58 </tx:attributes>59 </tx:advice>60 --Configure the entry point for the transaction: AOP cut-in-->62 <aop:config>63 <!--configuration Cut-in expression-->64 <aop:pointcut expression= "Execution (* Com.proc.service.*.* (..)) " Id= "Pointcut"/>65 <aop:advisor pointcut-ref= "pointcut" advice-ref= "Advice" ></aop:advisor>66 </ aop:config>67 </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 XML configuration-based transactions (14)

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.