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"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

	<!-- 读取 jdbc.properties -->
	<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:config/jdbc.properties</value>
			</list>
		</property>
	</bean>

	<!-- 配置数据源 -->
	<bean id="dataSourceLocal" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName" value="${jdbc.driverClassName}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		<property name="poolPreparedStatements" value="true" />
	</bean>

    <!-- 配置sqlMapClient -->
	<bean id="sqlMapClientLocal" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<property name="dataSource">
			<ref local="dataSourceLocal"/>
		</property>
		<property name="configLocation">
			<value>classpath:config/sqlMapConfig.xml</value>
		</property>
	</bean>
      
<!-- 以下为spring 事务设置,不过下面配置暂时有错,尚未处理 -->
  <bean id="transactionManagerLocal" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		   <property name="dataSource" ref="dataSourceLocal"/>
  </bean>
   <tx:advice id="txAdviceLocal" transaction-manager="transactionManagerLocal">
		<tx:attributes>
			<tx:method name="save*" propagation="REQUIRED" />
			<tx:method name="del*" propagation="REQUIRED" rollback-for="Exception"/>
			<tx:method name="insert*" propagation="REQUIRED" rollback-for="Exception" />
			<tx:method name="add*" propagation="REQUIRED" rollback-for="Exception" />
			<tx:method name="*" read-only="true" />
		</tx:attributes>
	</tx:advice>
	
	<aop:config proxy-target-class="true
"> <!--spring 默认的方式是接口,这里是写类-->
		<aop:pointcut id="allServiceMethod" expression="execution(public * com.service.impl.*.*(..))" />
		<aop:advisor advice-ref="txAdviceLocal" pointcut-ref="allServiceMethod" />
	</aop:config>
</beans>

 

你可能感兴趣的:(spring)