浏览 2180 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-03-07
<?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(); } } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-03-11
问题已经解决
|
|
返回顶楼 | |