日期:2014-05-19  浏览次数:20687 次

关于Spring配置事物管理的疑惑
<?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"  
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans  
  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop  
  http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx  
  http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/context 
  http://www.springframework.org/schema/context/spring-context-2.5.xsd" >
<context:annotation-config />
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="configLocation">
<value>
classpath:org/login/config.xml
</value>
</property>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
  <tx:method name="*" propagation="SUPPORTS" read-only="true"/>
  <tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
  <tx:method name="insert*" propagation="REQUIRED" read-only="false"/>
  <tx:method name="update*" propagation="REQUIRED" read-only="false"/>
  <tx:method name="del*" propagation="REQUIRED" read-only="false"/>
</tx:attributes>
</tx:advice>

<!--配置哪些类的方法需要进行事务管理 -->
<aop:config>
<aop:pointcut id="allManagerMethod"
expression="execution(* org.login.service.Impl.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" />
</aop:config>

<bean id="UserDAO" class="org.login.dao.Impl.UserDAO">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>
<bean id