Spring JTA应用JOTM:StandardXAPoolDataSource的使用

本节将介绍JOTM在Spring中的配置。


JOTM(Java Open Transaction Manager)是ObjectWeb的一个开源JTA实现,本身也是开源应用程序服务器JOnAS(Java Open Application Server)的一部分,为其提供JTA分布式事务的功能。Spring对JOTM提供了较好的支持,提供了一个org.springframework.transaction.jta.JotmFactoryBean的支持类,在Spring2.0中也包含了JOTM相关的一些library。

jotm的下载地址为http://jotm.objectweb.org,最新版本为2.0.10.

下载完成后解压缩,然后打开jotm下面conf文件夹,拷贝carol.properties文件到classpath中,并修改这个文件如下
carol.properties
Java代码 复制代码  收藏代码
  1. do not use CAROL JNDI wrapper      
  2. carol.start.jndi=false      
  3.       
  4. do not start a name server      
  5. carol.start.ns=false      
  6.       
  7. # Naming Factory   
  8. carol.jndi.java.naming.factory.url.pkgs=org.apache.naming  
# do not use CAROL JNDI wrapper   
carol.start.jndi=false   
   
# do not start a name server   
carol.start.ns=false   
   
# Naming Factory
carol.jndi.java.naming.factory.url.pkgs=org.apache.naming

上面配置文件的目的是不使用JNDI的方式来加载JOTM的配置,当然也可以根据需要选择其它的一些配置,例如JTOM所提供的默认配置。

然后开始在Spring上下文中配置JOTM,在classpath中建立一个ApplicationContext-jotm.xml,配置如下

ApplicationContext-jotm.xml
Java代码 复制代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">   
  5.   
  6.     <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>   
  7.        
  8.     <bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager">   
  9.         <property name="userTransaction" ref="jotm" />   
  10.     </bean>   
  11.   
  12.     <bean id="ds1" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown">   
  13.         <property name="dataSource">   
  14.             <bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown">   
  15.                 <property name="transactionManager" ref="jotm" />   
  16.                 <property name="driverName" value="com.mysql.jdbc.Driver" />   
  17.                 <property name="url" value="jdbc:MySQL://localhost:3306/test" />   
  18.             </bean>   
  19.         </property>   
  20.         <property name="user" value="root" />   
  21.         <property name="password" value="admin" />   
  22.     </bean>   
  23.        
  24.     <bean id="ds2" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown">   
  25.         <property name="dataSource">   
  26.             <bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown">   
  27.                 <property name="transactionManager" ref="jotm" />   
  28.                 <property name="driverName" value="com.mysql.jdbc.Driver" />   
  29.                 <property name="url" value="jdbc:MySQL://localhost:3306/test2" />   
  30.             </bean>   
  31.         </property>   
  32.         <property name="user" value="root" />   
  33.         <property name="password" value="admin" />   
  34.     </bean>   
  35.   
  36.     <bean id="template1" class="org.springframework.jdbc.core.JdbcTemplate">   
  37.         <property name="dataSource" ref="ds1" />   
  38.     </bean>   
  39.        
  40.     <bean id="template2" class="org.springframework.jdbc.core.JdbcTemplate">   
  41.         <property name="dataSource" ref="ds2" />   
  42.     </bean>   
  43.        
  44.     <bean id="dao1" class="com.xa.dao.UserDao1">   
  45.         <property name="jdbcTemplate">   
  46.             <ref bean="template1"></ref>   
  47.         </property>   
  48.     </bean>   
  49.        
  50.     <bean id="dao2" class="com.xa.dao.UserDao2">   
  51.         <property name="jdbcTemplate">   
  52.             <ref bean="template2"></ref>   
  53.         </property>   
  54.     </bean>   
  55.        
  56.     <bean id="userServiceTarget" class="com.xa.service.UserServiceImpl">   
  57.         <property name="dao1" ref="dao1"/>   
  58.         <property name="dao2" ref="dao2"/>   
  59.     </bean>   
  60.   
  61.   
  62.     <bean id="userTest" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">       
  63.         <property name="transactionManager">   
  64.             <ref bean="txManager"/>   
  65.         </property>       
  66.         <property name="target">   
  67.             <ref bean="userServiceTarget"/>   
  68.         </property>   
  69.         <property name="transactionAttributes">           
  70.             <props>   
  71.                 <prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop>               
  72.             </props>   
  73.         </property>   
  74.     </bean>   
  75. </beans>  
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

	<bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>
	
	<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager">
		<property name="userTransaction" ref="jotm" />
	</bean>

	<bean id="ds1" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown">
		<property name="dataSource">
			<bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown">
				<property name="transactionManager" ref="jotm" />
				<property name="driverName" value="com.mysql.jdbc.Driver" />
				<property name="url" value="jdbc:MySQL://localhost:3306/test" />
			</bean>
		</property>
		<property name="user" value="root" />
		<property name="password" value="admin" />
	</bean>
	
	<bean id="ds2" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown">
		<property name="dataSource">
			<bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown">
				<property name="transactionManager" ref="jotm" />
				<property name="driverName" value="com.mysql.jdbc.Driver" />
				<property name="url" value="jdbc:MySQL://localhost:3306/test2" />
			</bean>
		</property>
		<property name="user" value="root" />
		<property name="password" value="admin" />
	</bean>

	<bean id="template1" class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="ds1" />
	</bean>
	
	<bean id="template2" class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="ds2" />
	</bean>
	
	<bean id="dao1" class="com.xa.dao.UserDao1">
		<property name="jdbcTemplate">
			<ref bean="template1"></ref>
		</property>
	</bean>
	
	<bean id="dao2" class="com.xa.dao.UserDao2">
		<property name="jdbcTemplate">
			<ref bean="template2"></ref>
		</property>
	</bean>
	
	<bean id="userServiceTarget" class="com.xa.service.UserServiceImpl">
		<property name="dao1" ref="dao1"/>
		<property name="dao2" ref="dao2"/>
	</bean>


	<bean id="userTest" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">    
		<property name="transactionManager">
			<ref bean="txManager"/>
		</property>    
		<property name="target">
			<ref bean="userServiceTarget"/>
		</property>
		<property name="transactionAttributes">        
			<props>
				<prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop>            
			</props>
		</property>
	</bean>
</beans>

上面是一个完整的Spring上下文配置,可以看第一个bean “jotm”,实际上引用了Spring内部所提供的对JOTM支持的工厂类,参考下面的配置代码段
Java代码 复制代码  收藏代码
  1. <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>  
<bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>


随后,配置了JTA事务管理器,并且在管理器中使用上面所配置的jotm,如下面的代码
Java代码 复制代码  收藏代码
  1. <bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager">   
  2.     <property name="userTransaction" ref="jotm" />   
  3. </bean>  
<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager">
	<property name="userTransaction" ref="jotm" />
</bean>


再接下来就是配置多个数据源了,使用jotm提供的org.enhydra.jdbc.pool.StandardXAPoolDataSource类,根据类名可以明确地看出它是用以配置多个数据源的啦,配置的代码如下
Java代码 复制代码  收藏代码
  1. <bean id="ds1" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown">   
  2.         <property name="dataSource">   
  3.             <bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown">   
  4.                 <property name="transactionManager" ref="jotm" />   
  5.                 <property name="driverName" value="com.mysql.jdbc.Driver" />   
  6.                 <property name="url" value="jdbc:MySQL://localhost:3306/test" />   
  7.             </bean>   
  8.         </property>   
  9.         <property name="user" value="root" />   
  10.         <property name="password" value="admin" />   
  11.     </bean>   
  12.        
  13.     <bean id="ds2" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown">   
  14.         <property name="dataSource">   
  15.             <bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown">   
  16.                 <property name="transactionManager" ref="jotm" />   
  17.                 <property name="driverName" value="com.mysql.jdbc.Driver" />   
  18.                 <property name="url" value="jdbc:MySQL://localhost:3306/test2" />   
  19.             </bean>   
  20.         </property>   
  21.         <property name="user" value="root" />   
  22.         <property name="password" value="admin" />   
  23.     </bean>  
<bean id="ds1" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown">
		<property name="dataSource">
			<bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown">
				<property name="transactionManager" ref="jotm" />
				<property name="driverName" value="com.mysql.jdbc.Driver" />
				<property name="url" value="jdbc:MySQL://localhost:3306/test" />
			</bean>
		</property>
		<property name="user" value="root" />
		<property name="password" value="admin" />
	</bean>
	
	<bean id="ds2" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown">
		<property name="dataSource">
			<bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown">
				<property name="transactionManager" ref="jotm" />
				<property name="driverName" value="com.mysql.jdbc.Driver" />
				<property name="url" value="jdbc:MySQL://localhost:3306/test2" />
			</bean>
		</property>
		<property name="user" value="root" />
		<property name="password" value="admin" />
	</bean>

这里配置的两个数据源都连接到本地的mysql,实际上可以连接到不同的db server和不同类型的数据库,已经经过测试,这里为了方便,在本地建立了两个不同的数据库(test,test2)做测试。

随后的配置基本上和普通的Spring上下文配置相同了,根据不同的数据源配置两个jdbcTemplate,两个dao分别引用不同的jdbcTemplate, 将两个dao注入到UserService中, 最后将service纳入事务管理,并在事务代理配置中配置回滚规则,意思为如遇异常,则强制回滚内容。配置如下所示
Java代码 复制代码  收藏代码
  1. <property name="transactionAttributes">           
  2.     <props>   
  3.         <prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop>               
  4.     </props>   
  5. </property>  
<property name="transactionAttributes">        
	<props>
		<prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop>            
	</props>
</property>


这样,一个使用JOTM JTA事务的简单应用算大致成型了,最后,写一个JUnit,来测试一下结果
TestXa.java
Java代码 复制代码  收藏代码
  1. package com.xa;   
  2.   
  3. import org.springframework.context.ApplicationContext;   
  4. import org.springframework.test.AbstractDependencyInjectionSpringContextTests;   
  5.   
  6. import com.xa.service.UserService;   
  7.   
  8. public class TestXa extends AbstractDependencyInjectionSpringContextTests   
  9. {   
  10.     protected String[] getConfigLocations() {   
  11.         return new String[] { "classpath:ApplicationContext-jotm.xml" };   
  12.     }   
  13.   
  14.     public void testInsertBothDatabase() {   
  15.         ApplicationContext ctx = this.getApplicationContext();   
  16.         UserService ut = (UserService)ctx.getBean("userTest");   
  17.         try {   
  18.             ut.insertBothDatabase("1"null);   
  19.         }   
  20.         catch (Exception e) {   
  21.             e.printStackTrace();   
  22.         }   
  23.     }   
  24. }  
package com.xa;

import org.springframework.context.ApplicationContext;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;

import com.xa.service.UserService;

public class TestXa extends AbstractDependencyInjectionSpringContextTests
{
	protected String[] getConfigLocations() {
		return new String[] { "classpath:ApplicationContext-jotm.xml" };
	}

	public void testInsertBothDatabase() {
		ApplicationContext ctx = this.getApplicationContext();
		UserService ut = (UserService)ctx.getBean("userTest");
		try {
	        ut.insertBothDatabase("1", null);
        }
        catch (Exception e) {
        	e.printStackTrace();
        }
	}
}

在test中,调用了UserService的insertBothDatabase方法,有两个参数,userId和UserName,另外在方法的实现中调用了两个使用不同数据源dao,分别向两个不同的数据库插入输入,而test2数据库的xa_test表中,name字段是不允许为空的,因此,在插入test2数据库时会失败.

运行这个test,然后察看数据库结果:),test和test2数据库中都没有插入成功,看serviceImpl中的代码可以知道,逻辑上dao1会先于dao2执行,但是由于JTA事务,在dao2插入数据出现异常时整个事务被回滚,由于事务被配置在service层,dao1和dao2都被纳入一个事务进行管理,呵呵。修改一下方法的参数,修改为
Java代码 复制代码  收藏代码
  1. ut.insertBothDatabase("1""name1");  
ut.insertBothDatabase("1", "name1");


然后再试试test看数据库结果,如何?

1.web.xml

 

Java代码 复制代码  收藏代码
  1. <servlet>   
  2.         <servlet-name>Dispatcher</servlet-name>   
  3.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>   
  4.         <init-param>   
  5.             <param-name>contextConfigLocation</param-name>   
  6.             <param-value>/WEB-INF/classes/applicationContext.xml</param-value>   
  7.         </init-param>   
  8.         <load-on-startup>1</load-on-startup>   
  9.     </servlet>   
  10.     <servlet-mapping>   
  11.         <servlet-name>Dispatcher</servlet-name>   
  12.         <url-pattern>*.do</url-pattern>   
  13.     </servlet-mapping>  
<servlet>
		<servlet-name>Dispatcher</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>Dispatcher</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>

 2.加入编码格式

Java代码 复制代码  收藏代码
  1. <filter>   
  2.         <filter-name>Set Character Encoding</filter-name>   
  3.         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>   
  4.         <init-param>   
  5.             <param-name>encoding</param-name>   
  6.             <param-value>UTF-8</param-value>   
  7.         </init-param>   
  8.     </filter>   
  9.     <filter-mapping>   
  10.         <filter-name>Set Character Encoding</filter-name>   
  11.         <url-pattern>/*</url-pattern>   
  12.     </filter-mapping>  
<filter>
		<filter-name>Set Character Encoding</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>Set Character Encoding</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

 3.由于spring 3.0 里不在提供对jotm的封装,我们可以手动的编写加入代码如下

 

Java代码 复制代码  收藏代码
  1. /*  
  2.  * Copyright 20010-2011  
  3.  */  
  4.   
  5. package com.demo.spring.jotm;   
  6.   
  7. import javax.naming.NamingException;   
  8. import javax.transaction.SystemException;   
  9.   
  10. import org.objectweb.jotm.Current;   
  11. import org.objectweb.jotm.Jotm;   
  12.   
  13. import org.springframework.beans.factory.DisposableBean;   
  14. import org.springframework.beans.factory.FactoryBean;   
  15.   
  16. /**  
  17.  * @author fenglingcorp  
  18.  */  
  19. @SuppressWarnings("rawtypes")   
  20. public class JotmFactoryBean implements FactoryBean, DisposableBean {   
  21.   
  22.     private Current jotmCurrent;   
  23.   
  24.     private Jotm jotm;   
  25.   
  26.     public JotmFactoryBean() throws NamingException {   
  27.         // Check for already active JOTM instance.   
  28.         this.jotmCurrent = Current.getCurrent();   
  29.   
  30.         // If none found, create new local JOTM instance.   
  31.         if (this.jotmCurrent == null) {   
  32.             // Only for use within the current Spring context:   
  33.             // local, not bound to registry.   
  34.             this.jotm = new Jotm(truefalse);   
  35.             this.jotmCurrent = Current.getCurrent();   
  36.         }   
  37.     }   
  38.   
  39.     public void setDefaultTimeout(int defaultTimeout) {   
  40.         this.jotmCurrent.setDefaultTimeout(defaultTimeout);   
  41.         // The following is a JOTM oddity: should be used for demarcation   
  42.         // transaction only,   
  43.         // but is required here in order to actually get rid of JOTM's default   
  44.         // (60 seconds).   
  45.         try {   
  46.             this.jotmCurrent.setTransactionTimeout(defaultTimeout);   
  47.         } catch (SystemException ex) {   
  48.             // should never happen   
  49.         }   
  50.     }   
  51.   
  52.     public Jotm getJotm() {   
  53.         return this.jotm;   
  54.     }   
  55.   
  56.     public Object getObject() {   
  57.         return this.jotmCurrent;   
  58.     }   
  59.   
  60.     public Class getObjectType() {   
  61.         return this.jotmCurrent.getClass();   
  62.     }   
  63.   
  64.     public boolean isSingleton() {   
  65.         return true;   
  66.     }   
  67.   
  68.     public void destroy() {   
  69.         if (this.jotm != null) {   
  70.             this.jotm.stop();   
  71.         }   
  72.     }   
  73.   
  74. }  
/*
 * Copyright 20010-2011
 */

package com.demo.spring.jotm;

import javax.naming.NamingException;
import javax.transaction.SystemException;

import org.objectweb.jotm.Current;
import org.objectweb.jotm.Jotm;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;

/**
 * @author fenglingcorp
 */
@SuppressWarnings("rawtypes")
public class JotmFactoryBean implements FactoryBean, DisposableBean {

	private Current jotmCurrent;

	private Jotm jotm;

	public JotmFactoryBean() throws NamingException {
		// Check for already active JOTM instance.
		this.jotmCurrent = Current.getCurrent();

		// If none found, create new local JOTM instance.
		if (this.jotmCurrent == null) {
			// Only for use within the current Spring context:
			// local, not bound to registry.
			this.jotm = new Jotm(true, false);
			this.jotmCurrent = Current.getCurrent();
		}
	}

	public void setDefaultTimeout(int defaultTimeout) {
		this.jotmCurrent.setDefaultTimeout(defaultTimeout);
		// The following is a JOTM oddity: should be used for demarcation
		// transaction only,
		// but is required here in order to actually get rid of JOTM's default
		// (60 seconds).
		try {
			this.jotmCurrent.setTransactionTimeout(defaultTimeout);
		} catch (SystemException ex) {
			// should never happen
		}
	}

	public Jotm getJotm() {
		return this.jotm;
	}

	public Object getObject() {
		return this.jotmCurrent;
	}

	public Class getObjectType() {
		return this.jotmCurrent.getClass();
	}

	public boolean isSingleton() {
		return true;
	}

	public void destroy() {
		if (this.jotm != null) {
			this.jotm.stop();
		}
	}

}

 4.加入jotm事务和xpool数据源

Java代码 复制代码  收藏代码
  1. <!-- jotm -->   
  2.     <bean id="jotm" class="com.demo.spring.jotm.JotmFactoryBean" />   
  3.   
  4.     <bean id="transactionManager"  
  5.         class="org.springframework.transaction.jta.JtaTransactionManager">   
  6.         <property name="userTransaction" ref="jotm" />   
  7.     </bean>   
  8.   
  9.     <!-- StandardXAPoolDataSourc 数据源 -->   
  10.     <bean id="dataSource" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource">   
  11.         <property name="dataSource">   
  12.             <bean id="innerDataSource" class="org.enhydra.jdbc.standard.StandardXADataSource">   
  13.                 <property name="transactionManager">   
  14.                     <ref local="jotm" />   
  15.                 </property>   
  16.                 <property name="driverName">   
  17.                     <value>${datasource.driverClassName}</value>   
  18.                 </property>   
  19.                 <property name="url">   
  20.                     <value>${datasource.g_db_w_url}</value>   
  21.                 </property>   
  22.                 <property name="user">   
  23.                     <value>${datasource.g_db_w_username}</value>   
  24.                 </property>   
  25.                 <property name="password">   
  26.                     <value>${datasource.g_db_w_password}</value>   
  27.                 </property>   
  28.             </bean>   
  29.         </property>   
  30.         <property name="user">   
  31.             <value>${datasource.g_db_w_username}</value>   
  32.         </property>   
  33.         <property name="password">   
  34.             <value>${datasource.g_db_w_password}</value>   
  35.         </property>   
  36.         <property name="maxSize">   
  37.             <value>5</value>   
  38.         </property>   
  39.         <property name="minSize">   
  40.             <value>2</value>   
  41.         </property>   
  42.     </bean>  
<!-- jotm -->
	<bean id="jotm" class="com.demo.spring.jotm.JotmFactoryBean" />

	<bean id="transactionManager"
		class="org.springframework.transaction.jta.JtaTransactionManager">
		<property name="userTransaction" ref="jotm" />
	</bean>

	<!-- StandardXAPoolDataSourc 数据源 -->
	<bean id="dataSource" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource">
		<property name="dataSource">
			<bean id="innerDataSource" class="org.enhydra.jdbc.standard.StandardXADataSource">
				<property name="transactionManager">
					<ref local="jotm" />
				</property>
				<property name="driverName">
					<value>${datasource.driverClassName}</value>
				</property>
				<property name="url">
					<value>${datasource.g_db_w_url}</value>
				</property>
				<property name="user">
					<value>${datasource.g_db_w_username}</value>
				</property>
				<property name="password">
					<value>${datasource.g_db_w_password}</value>
				</property>
			</bean>
		</property>
		<property name="user">
			<value>${datasource.g_db_w_username}</value>
		</property>
		<property name="password">
			<value>${datasource.g_db_w_password}</value>
		</property>
		<property name="maxSize">
			<value>5</value>
		</property>
		<property name="minSize">
			<value>2</value>
		</property>
	</bean>

 5.加入aop支持

Java代码 复制代码  收藏代码
  1. <aop:config>   
  2.         <aop:pointcut id="serviceMethods"  
  3.             expression="execution(* com.demo.spring.dao.*.*(..))" />   
  4.         <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods" />   
  5.     </aop:config>   
  6.     <tx:advice id="txAdvice" transaction-manager="transactionManager">   
  7.         <tx:attributes>   
  8.             <tx:method name="add*" rollback-for="Exception" />   
  9.             <tx:method name="insert*" rollback-for="Exception" />   
  10.             <tx:method name="save*" rollback-for="Exception" />   
  11.             <tx:method name="update*" rollback-for="Exception" />   
  12.             <tx:method name="del*" rollback-for="Exception" />   
  13.             <tx:method name="remove*" rollback-for
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值