spring xml-based declarative transaction steps to control


<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!--配置业务层--> <bean id="accountService" class="com.com.service.impl.AccountServiceImpl"> <property name="accountDao" ref="accountDao"></property> </bean> <!--配置持久层--> <bean id="accountDao" class="com.com.dao.impl.AccountDaoImpl"> <property name="dataSource" ref="dataSource"></property> </bean> <!--<!–Object Configuration JdbcTemplate ndash &; & class<the bean ID = "the jdbcTemplate"gt; ="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource"></property> </bean>--> <!--配置数据源 使用spring的内置数据源--> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/spring"></property> <property name="username" value="root"></property> <property name="password" value="root"></property> </ the bean> Use tx: advice notification tag configuration transaction2configuration transaction manager. 1spirng steps to control the xml-based transaction statement ! <-. notification configuration transaction Properties: the above mentioned id: starting to notice a transaction that uniquely identifies Transaction - Manager: to notify a transaction manager transaction references, 3 configuration common entry point for the expression of AOP. 4 establishing correspondence between the transaction and the starting point of the expression. 5 configuration. property transactions in tx: advice internal label using tx: attributes tab to configure the tx: attributes internal label using tx: method tag attributes: name: Add transaction management method name can use wildcard * , indicating that all methods will have transaction management and affairs follow-configured transaction attributes, query methods can find use * , set the transaction property alone, so named best method to follow naming conventions, such as the query method to find the beginning of the find * has higher precedence than * isolation: for the specified transaction isolation level, the default is DEFAULT, represents the default isolation level using a database of propagation: propagation behavior for the specified transaction, default is REQUIRED, it indicates there will be a transaction, additions and deletions to the selection, query method you can choose SUPPORTS, the read - only: used to specify whether a transaction is read-only query method can be set to true, the default value is false, meaning to read and write timeout: timeout for the specified transaction, the default value is -1 , expressed not timeout, if the value is specified in seconds rOLLBACK - for : used to specify an exception when the exception occurs, the transaction is rolled back, produce other abnormalities, the transaction is not rolled back, no default value, indicating any abnormality will return roll ON -rollback- for : used to specify an exception when the exception occurs, the transaction is not rolled back, produce other abnormalities, the transaction is rolled back, no default value, indicating any abnormalities are rolled back -> <-! Configuring transaction Manager -> <bean the above mentioned id = "transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!--配置事务的通知--> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <!--配置事务的属性--> <tx:attributes> <tx:method name="*" propagation="REQUIRED" read-only="false"/> <tx:method name="find*" propagation="SUPPORTS" read-only="true"/> </tx:attributes> </tx:advice> <!--配置AOP--> <aop:config> <AOP: the pointcut ID = "PT1" = expression The "Execution (com.com.service.impl * * * (..)..)" /> <! - General configuration pointcut expression of AOP -> <! - expressions establish Affairs and the starting point of correspondence between the -> <AOP: Advisor advice-ref = "txAdvice" pointcut-ref = "PT1 "> </ aop: advisor> </ AOP: config> </ Beans>

spring xml-based declarative transaction steps to control

Guess you like

Origin www.cnblogs.com/wqy0314/p/11888428.html