关于JOTM配置全局事务的问题,实在是没办法了

xml配置如下

<?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:jee="http://www.springframework.org/schema/jee"
	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/jee http://www.springframework.org/schema/jee/spring-jee-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">

	
	<aop:config proxy-target-class="true">
		<aop:advisor pointcut="execution(* com.ctvit.test.struts.TestSerivce.*(..))" advice-ref="txAdvice" />
	</aop:config>
		
	<tx:advice id="txAdvice" transaction-manager="transactionManager"> 
		<tx:attributes>
		<tx:method name="save*"/>
		<tx:method name="test*"/>
		<tx:method name="*" read-only="true" />		
		</tx:attributes>
	</tx:advice>
	
	<bean id="jotmJta" class="org.springframework.transaction.jta.JotmFactoryBean" />
	
	<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
		<property name="userTransaction" ref="jotmJta" />
	</bean>
	<tx:annotation-driven transaction-manager="transactionManager"/> 
	
	
	<bean id="ds1" class="org.apache.commons.dbcp.BasicDataSource" 	destroy-method="close">
		<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
		<property name="url" value="jdbc:oracle:thin:@192.168.168.171:1521:cctveip" />
		<property name="username" value="a" />
		<property name="password" value="a" />
	</bean>	

	<bean id="sessionFactory1"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource">
			<ref bean="ds1" />
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
			</props>
		</property>
		<property name="mappingResources">
			<list>
				<value>com/ctvit/test/domain/YbTest1.hbm.xml</value>
				<value>com/ctvit/test/domain/YbTest2.hbm.xml</value>
			</list>
		</property>
	</bean>

	<bean id="testSerivce" class="com.ctvit.test.struts.TestSerivce">
		<property name="tes1Dao" ref="YbTest1DAO"></property>
		<property name="tes2Dao" ref="YbTest2DAO"></property>
	</bean>
	
	<bean id="YbTest1DAO" class="com.ctvit.test.domain.YbTest1DAO">
		<property name="sessionFactory">
			<ref bean="sessionFactory1" />
		</property>
	</bean>
	<bean id="YbTest2DAO" class="com.ctvit.test.domain.YbTest2DAO">
		<property name="sessionFactory">
			<ref bean="sessionFactory1" />
		</property>
	</bean>
</beans>


java 测试代码如下

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

import com.ctvit.test.struts.TestSerivce;

public class TestXa extends AbstractDependencyInjectionSpringContextTests  {
	protected String[] getConfigLocations() {
		return new String[] { "classpath:applicationContext.xml" };
	}
	public void testJOTM()  {
		ApplicationContext ctx = this.getApplicationContext();
		TestSerivce testSerivce = (TestSerivce)ctx.getBean("testSerivce");
		
		try {			
			testSerivce.saveTest();			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}
}

你可能感兴趣的:(java,xml,Hibernate,struts)