锘??xml version="1.0" encoding="utf-8" standalone="yes"?>在线国产网址,国产精品二三区,国产精品久久久久9999赢消http://www.aygfsteel.com/kyleYang/category/43031.html姣忎釜浜洪兘渚濋潬鑷繁鐨勭煡璇嗗拰璁よ瘑錛屽嵈鍙堣鍏舵墍鏉熺細錛岃繕灝嗚繖浜涚О涓虹幇瀹烇紝浣嗘槸鐭ヨ瘑鍜岃璇嗘槸闈炲父鏆ф槯鐨勪笢瑗匡紝閭d釜鐜板疄涔熻涓嶈繃鍙槸騫昏銆備漢浠兘媧誨湪鑷垜鎰忚瘑涔嬩腑銆?/description>zh-cnWed, 09 Dec 2009 19:31:35 GMTWed, 09 Dec 2009 19:31:35 GMT60Spring JTA 浜嬪姟灝忚http://www.aygfsteel.com/kyleYang/articles/305314.html椋炵唺椋炵唺Wed, 09 Dec 2009 09:29:00 GMThttp://www.aygfsteel.com/kyleYang/articles/305314.htmlhttp://www.aygfsteel.com/kyleYang/comments/305314.htmlhttp://www.aygfsteel.com/kyleYang/articles/305314.html#Feedback0http://www.aygfsteel.com/kyleYang/comments/commentRss/305314.htmlhttp://www.aygfsteel.com/kyleYang/services/trackbacks/305314.html閲囩敤atomikos鐨刯ta浜嬪姟錛堣鎰熻阿 http://andyao.javaeye.com/錛?
<?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">

<bean id="dataSource" class="com.atomikos.jdbc.SimpleDataSourceBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName">
<value>mysql/main</value>
</property>
<property name="xaDataSourceClassName">
<!--浣跨敤Mysql XADataSource(mysql>=5.0, Connector/J>=5.0鎵嶅彲浠ユ敮鎸乆ADatasource)-->
<value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
</property>
<property name="xaDataSourceProperties">
<value>URL=jdbc:mysql://localhost:3306/crm?useUnicode=true&amp;characterEncoding=UTF-8;user=root;password=root</value>
</property>
<property name="exclusiveConnectionMode">
<value>true</value>
</property>
<property name="connectionPoolSize">
<value>3</value>
</property>
<property name="validatingQuery">
<value>SELECT 1</value>
</property>
</bean>
<!-- 絎簩涓暟鎹簱 -->
<bean id="dataSourceB" class="com.atomikos.jdbc.SimpleDataSourceBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName">
<value>mysql/news</value>
</property>
<property name="xaDataSourceClassName">
<!--
浣跨敤Mysql XADataSource(mysql>=5.0, Connector/J>=5.0鎵嶅彲浠ユ敮鎸乆ADatasource)
-->
<value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
</property>
<property name="xaDataSourceProperties">
<value>URL=jdbc:mysql://localhost:3306/crm2?useUnicode=true&amp;characterEncoding=UTF-8;user=root;password=root</value>
</property>
<property name="exclusiveConnectionMode">
<value>true</value>
</property>
<property name="connectionPoolSize">
<value>3</value>
</property>
<property name="validatingQuery">
<value>SELECT 1</value>
</property>
</bean>

<bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" />

<!-- 絎竴涓暟鎹簱鐨剆qlMapClient -->
<bean id="sqlMapClient1" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<!-- 鍖呭惈絎竴涓暟鎹簱琛ㄧ殑map -->
<value>classpath:SqlMapConfig.xml</value>
</property>
<property name="dataSource" ref="dataSource" />
<property name="lobHandler" ref="lobHandler" />
</bean>
<!-- 絎簩涓暟鎹簱鐨剆qlMapClient -->
<bean id="sqlMapClient2" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<!-- 鍖呭惈絎竴涓暟鎹簱琛ㄧ殑map -->
<value>classpath:SqlMapConfig2.xml</value>
</property>
<property name="dataSource" ref="dataSourceB" />
<property name="lobHandler" ref="lobHandler" />
</bean>

<!-- Optional: add a log administrator -->
<bean id="localLogAdministrator"
class="com.atomikos.icatch.admin.imp.LocalLogAdministrator"/>

<bean id="userTransactionService"
聽 class="com.atomikos.icatch.config.UserTransactionServiceImp"
聽 init-method="init" destroy-method="shutdownForce">
聽聽聽 <constructor-arg>
聽聽聽聽聽聽聽 <!-- IMPORTANT: specify all Atomikos properties here -->
聽聽聽聽聽聽聽 <props>
聽聽聽聽聽聽聽聽聽聽聽 <prop key="com.atomikos.icatch.service">com.atomikos.icatch.standalone.UserTransactionServiceFactory</prop>
聽聽聽聽聽聽聽 </props>
聽聽聽 </constructor-arg>
聽聽聽 <property name="initialLogAdministrators">
聽聽聽聽聽聽聽 <list>
聽聽聽聽聽聽聽聽聽聽聽 <ref bean="localLogAdministrator"/>
聽聽聽聽聽聽聽 </list>
聽聽聽 </property>
</bean>
<!--Construct Atomikos UserTransactionManager,needed to configure Spring -->
<bean id="AtomikosTransactionManager"
聽聽聽聽聽 class="com.atomikos.icatch.jta.UserTransactionManager"
聽聽聽聽聽 init-method="init" destroy-method="close"
聽聽聽聽聽 depends-on="userTransactionService">
聽聽 <!--when close is called,should we force transactions to terminate or not?-->
聽聽 <property name="forceShutdown" value="false" />
</bean>
聽聽 <!--Also use Atomikos UserTransactionImp, needed to configure Spring-->
<bean id="AtomikosUserTransaction"
聽聽聽聽聽 class="com.atomikos.icatch.jta.UserTransactionImp"聽
聽聽聽聽聽 depends-on="userTransactionService">
聽聽 <property name="transactionTimeout" value="300" />
</bean>
聽聽 <!-- Configure the Spring framework to use JTA transactions from Atomikos -->
<bean id="JtaTransactionManager"
聽聽聽聽聽 class="org.springframework.transaction.jta.JtaTransactionManager"
聽聽聽聽聽 depends-on="userTransactionService">
聽聽 <property name="transactionManager" ref="AtomikosTransactionManager" />
聽聽 <property name="userTransaction" ref="AtomikosUserTransaction" />
</bean>

<bean id="user1Dao" class="com.crm.code.dao.impl.User1DaoImpl">
<property name="sqlMapClient">
<ref bean="sqlMapClient1"/>
</property>
</bean>
<bean id="user2Dao" class="com.crm.code.dao.impl.User2DaoImpl">
<property name="sqlMapClient">
<ref bean="sqlMapClient2"/>
</property>
</bean>
<bean id="user12Service" class="com.crm.code.service.impl.User12ServiceImpl">
<property name="user1Dao">
<ref bean="user1Dao" />
</property>
<property name="user2Dao">
<ref bean="user2Dao" />
</property>
</bean>

</beans>
榪欐牱鏄垚鍔熺殑 鍙槸鍒囨崲oracle9i鏃舵偛鍓у彂鐢熶簡
--- Cause: com.atomikos.datasource.ResourceException: resume for XID oracle.jdbc.xa.OracleXid@145f939 raised -3: the XA resource detected an internal error
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:聽聽
--- The error occurred in ibatis/Product1.xml.聽
--- The error occurred while executing update.聽
--- Check the聽聽聽聽聽聽聽聽聽 insert into boss_product聽聽聽聽 (PROD_ID,聽 PARENT_ID,聽 APP_ID,聽 PROD_NAME,聽 PROD_CODE,聽 DEFAULT_VER_PROD_ID,聽 DATA_PATH,聽 GMT_CREATED,聽 GMT_MODIFIED,聽 CREATOR,聽 MODIFIER,聽 IS_DELETED)聽聽聽聽聽 values聽聽聽聽 (seq_boss_product.nextval,聽聽聽聽聽 1,聽聽聽聽聽 88,聽聽聽聽聽 ?,聽聽聽聽聽 ?,聽聽聽聽聽 10,聽聽聽聽聽 'aaa',聽聽聽聽聽 sysdate,聽聽聽聽聽 sysdate,聽聽聽聽聽 'aavv',聽聽聽聽聽 'aacb',聽聽聽聽聽 'n')聽聽聽聽聽聽聽 .聽

瀹樻柟璇磑racle榪炴帴闂 鍝庛傘傘傛棤璇簡
鎹簡涓縐岼TA浜嬪姟鏈哄埗 閫氳繃JOTM
<?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">
聽聽聽聽聽聽聽聽聽聽
聽聽 <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="dataSourceA" 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="oracle.jdbc.driver.OracleDriver"/>聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <property name="url" value="jdbc:oracle:thin:@10.2.224.44:1521:trade"/>聽
聽聽聽聽聽聽聽聽聽聽聽聽 </bean>聽
聽聽聽聽聽聽聽聽 </property>聽
聽聽聽聽聽聽聽聽 <property name="user" value="crm_aep"/>聽
聽聽聽聽聽聽聽聽 <property name="password" value="crm_aep"/>聽
聽聽聽聽 </bean>聽

聽聽聽 <bean id="dataSourceB" 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="oracle.jdbc.driver.OracleDriver"/>聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <property name="url" value="jdbc:oracle:thin:@10.2.226.24:1521:voucher"/>聽
聽聽聽聽聽聽聽聽聽聽聽聽 </bean>聽
聽聽聽聽聽聽聽聽 </property>聽
聽聽聽聽聽聽聽聽 <property name="user" value="boss"/>聽
聽聽聽聽聽聽聽聽 <property name="password" value="boss"/>聽
聽聽聽聽 </bean>聽

聽聽聽 <tx:annotation-driven transaction-manager="txManager" proxy-target-class="true" />
聽聽聽聽聽聽聽聽聽聽
<!-- 絎竴涓暟鎹簱鐨剆qlMapClient -->
<bean id="sqlMapClient1" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<!-- 鍖呭惈絎竴涓暟鎹簱琛ㄧ殑map -->
<value>classpath:SqlMapConfig_ora1.xml</value>
</property>
<property name="dataSource" ref="dataSourceA" />
</bean>
<!-- 絎簩涓暟鎹簱鐨剆qlMapClient -->
<bean id="sqlMapClient2" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<!-- 鍖呭惈絎竴涓暟鎹簱琛ㄧ殑map -->
<value>classpath:SqlMapConfig_ora2.xml</value>
</property>
<property name="dataSource" ref="dataSourceB" />
</bean>


<bean id="product1Dao" class="com.crm.code.dao.impl.Product1DaoImpl">
<property name="sqlMapClient">
<ref bean="sqlMapClient1"/>
</property>
</bean>
<bean id="product2Dao" class="com.crm.code.dao.impl.Product2DaoImpl">
<property name="sqlMapClient">
<ref bean="sqlMapClient2"/>
</property>
</bean>
<bean id="product12Service" class="com.crm.code.service.impl.Product12ServiceImpl">
<property name="product1Dao">
<ref bean="product1Dao" />
</property>
<property name="product2Dao">
<ref bean="product2Dao" />
</property>
</bean>
</beans>


椋炵唺 2009-12-09 17:29 鍙戣〃璇勮
]]>
Spring涓泦鎴怞OTM 閰嶇疆JTA浜嬪姟http://www.aygfsteel.com/kyleYang/articles/305298.html椋炵唺椋炵唺Wed, 09 Dec 2009 08:41:00 GMThttp://www.aygfsteel.com/kyleYang/articles/305298.htmlhttp://www.aygfsteel.com/kyleYang/comments/305298.htmlhttp://www.aygfsteel.com/kyleYang/articles/305298.html#Feedback0http://www.aygfsteel.com/kyleYang/comments/commentRss/305298.htmlhttp://www.aygfsteel.com/kyleYang/services/trackbacks/305298.html闃呰鍏ㄦ枃

椋炵唺 2009-12-09 16:41 鍙戣〃璇勮
]]>
Spring JTA搴旂敤涔婮OTM閰嶇疆 http://www.aygfsteel.com/kyleYang/articles/305293.html椋炵唺椋炵唺Wed, 09 Dec 2009 08:34:00 GMThttp://www.aygfsteel.com/kyleYang/articles/305293.htmlhttp://www.aygfsteel.com/kyleYang/comments/305293.htmlhttp://www.aygfsteel.com/kyleYang/articles/305293.html#Feedback0http://www.aygfsteel.com/kyleYang/comments/commentRss/305293.htmlhttp://www.aygfsteel.com/kyleYang/services/trackbacks/305293.html
JOTM(Java Open Transaction Manager)鏄疧bjectWeb鐨勪竴涓紑婧怞TA瀹炵幇錛屾湰韜篃鏄紑婧愬簲鐢ㄧ▼搴忔湇鍔″櫒JOnAS(Java Open Application Server)鐨勪竴閮ㄥ垎錛屼負鍏舵彁渚汮TA鍒嗗竷寮忎簨鍔$殑鍔熻兘銆係pring瀵笿OTM鎻愪緵浜嗚緝濂界殑鏀寔錛屾彁渚涗簡涓涓猳rg.springframework.transaction.jta.JotmFactoryBean鐨勬敮鎸佺被錛屽湪Spring2.0涓篃鍖呭惈浜咼OTM鐩稿叧鐨勪竴浜沴ibrary銆?

jotm鐨勪笅杞藉湴鍧涓篽ttp://jotm.objectweb.org,鏈鏂扮増鏈負2.0.10.

涓嬭澆瀹屾垚鍚庤В鍘嬬緝錛岀劧鍚庢墦寮jotm涓嬮潰conf鏂囦歡澶癸紝鎷瘋礉carol.properties鏂囦歡鍒癱lasspath涓紝騫朵慨鏀硅繖涓枃浠跺涓?
carol.properties
Java浠g爜
  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聽聽

涓婇潰閰嶇疆鏂囦歡鐨勭洰鐨勬槸涓嶄嬌鐢↗NDI鐨勬柟寮忔潵鍔犺澆JOTM鐨勯厤緗紝褰撶劧涔熷彲浠ユ牴鎹渶瑕侀夋嫨鍏跺畠鐨勪竴浜涢厤緗紝渚嬪JTOM鎵鎻愪緵鐨勯粯璁ら厤緗?

鐒跺悗寮濮嬪湪Spring涓婁笅鏂囦腑閰嶇疆JOTM錛屽湪classpath涓緩绔嬩竴涓狝pplicationContext-jotm.xml錛岄厤緗涓?

ApplicationContext-jotm.xml
Java浠g爜
  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>聽聽

涓婇潰鏄竴涓畬鏁寸殑Spring涓婁笅鏂囬厤緗紝鍙互鐪嬬涓涓猙ean 鈥渏otm鈥濓紝瀹為檯涓婂紩鐢ㄤ簡Spring鍐呴儴鎵鎻愪緵鐨勫JOTM鏀寔鐨勫伐鍘傜被錛屽弬鑰冧笅闈㈢殑閰嶇疆浠g爜孌?
Java浠g爜
  1. <bean聽id="jotm"class="org.springframework.transaction.jta.JotmFactoryBean"/>聽聽


闅忓悗錛岄厤緗簡JTA浜嬪姟綆$悊鍣紝騫朵笖鍦ㄧ鐞嗗櫒涓嬌鐢ㄤ笂闈㈡墍閰嶇疆鐨刯otm錛屽涓嬮潰鐨勪唬鐮?
Java浠g爜
  1. <bean聽id="txManager"class="org.springframework.transaction.jta.JtaTransactionManager"> 聽聽
  2. 聽聽聽聽<property聽name="userTransaction"聽ref="jotm"聽/> 聽聽
  3. </bean>聽聽


鍐嶆帴涓嬫潵灝辨槸閰嶇疆澶氫釜鏁版嵁婧愪簡錛屼嬌鐢╦otm鎻愪緵鐨刼rg.enhydra.jdbc.pool.StandardXAPoolDataSource綾伙紝鏍規嵁綾誨悕鍙互鏄庣‘鍦扮湅鍑哄畠鏄敤浠ラ厤緗涓暟鎹簮鐨勫暒,閰嶇疆鐨勪唬鐮佸涓?
Java浠g爜
  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>聽聽

榪欓噷閰嶇疆鐨勪袱涓暟鎹簮閮借繛鎺ュ埌鏈湴鐨刴ysql錛屽疄闄呬笂鍙互榪炴帴鍒頒笉鍚岀殑db server鍜屼笉鍚岀被鍨嬬殑鏁版嵁搴擄紝宸茬粡緇忚繃嫻嬭瘯錛岃繖閲屼負浜嗘柟渚匡紝鍦ㄦ湰鍦板緩绔嬩簡涓や釜涓嶅悓鐨勬暟鎹簱(test,test2)鍋氭祴璇曘?

闅忓悗鐨勯厤緗熀鏈笂鍜屾櫘閫氱殑Spring涓婁笅鏂囬厤緗浉鍚屼簡錛屾牴鎹笉鍚岀殑鏁版嵁婧愰厤緗袱涓猨dbcTemplate錛屼袱涓猟ao鍒嗗埆寮曠敤涓嶅悓鐨刯dbcTemplate, 灝嗕袱涓猟ao娉ㄥ叆鍒癠serService涓? 鏈鍚庡皢service綰沖叆浜嬪姟綆$悊,騫跺湪浜嬪姟浠g悊閰嶇疆涓厤緗洖婊氳鍒?鎰忔濅負濡傞亣寮傚父錛屽垯寮哄埗鍥炴粴鍐呭銆傞厤緗涓嬫墍紺?
Java浠g爜
  1. <property聽name="transactionAttributes">聽聽聽聽聽聽聽聽 聽聽
  2. 聽聽聽聽<props> 聽聽
  3. 聽聽聽聽聽聽聽聽<prop聽key="insert*">PROPAGATION_REQUIRED,-Exception</prop>聽聽聽聽聽聽聽聽聽聽聽聽 聽聽
  4. 聽聽聽聽</props> 聽聽
  5. </property>聽聽


榪欐牱錛屼竴涓嬌鐢↗OTM JTA浜嬪姟鐨勭畝鍗曞簲鐢ㄧ畻澶ц嚧鎴愬瀷浜嗭紝鏈鍚庯紝鍐欎竴涓狫Unit錛屾潵嫻嬭瘯涓涓嬬粨鏋?
TestXa.java
Java浠g爜
  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. publicclass聽TestXa聽extends聽AbstractDependencyInjectionSpringContextTests 聽聽
  9. { 聽聽
  10. 聽聽聽聽protected聽String[]聽getConfigLocations()聽{ 聽聽
  11. 聽聽聽聽聽聽聽聽returnnew聽String[]聽{聽"classpath:ApplicationContext-jotm.xml"聽}; 聽聽
  12. 聽聽聽聽} 聽聽
  13. 聽聽
  14. 聽聽聽聽publicvoid聽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. }聽聽

鍦╰est涓紝璋冪敤浜哢serService鐨刬nsertBothDatabase鏂規硶錛屾湁涓や釜鍙傛暟錛寀serId鍜孶serName錛屽彟澶栧湪鏂規硶鐨勫疄鐜頒腑璋冪敤浜嗕袱涓嬌鐢ㄤ笉鍚屾暟鎹簮dao錛屽垎鍒悜涓や釜涓嶅悓鐨勬暟鎹簱鎻掑叆杈撳叆錛岃宼est2鏁版嵁搴撶殑xa_test琛ㄤ腑錛宯ame瀛楁鏄笉鍏佽涓虹┖鐨勶紝鍥犳錛屽湪鎻掑叆test2鏁版嵁搴撴椂浼氬け璐?

榪愯榪欎釜test錛岀劧鍚庡療鐪嬫暟鎹簱緇撴灉錛氾級錛宼est鍜宼est2鏁版嵁搴撲腑閮芥病鏈夋彃鍏ユ垚鍔燂紝鐪媠erviceImpl涓殑浠g爜鍙互鐭ラ亾錛岄昏緫涓奷ao1浼氬厛浜巇ao2鎵ц錛屼絾鏄敱浜嶫TA浜嬪姟錛屽湪dao2鎻掑叆鏁版嵁鍑虹幇寮傚父鏃舵暣涓簨鍔¤鍥炴粴錛岀敱浜庝簨鍔¤閰嶇疆鍦╯ervice灞傦紝dao1鍜宒ao2閮借綰沖叆涓涓簨鍔¤繘琛岀鐞嗭紝鍛靛懙銆備慨鏀逛竴涓嬫柟娉曠殑鍙傛暟錛屼慨鏀逛負
Java浠g爜
  1. ut.insertBothDatabase("1",聽"name1");聽聽


鐒跺悗鍐嶈瘯璇晅est鐪嬫暟鎹簱緇撴灉錛屽浣曪紵


椋炵唺 2009-12-09 16:34 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 平邑县| 宁津县| 巴林右旗| 饶阳县| 若尔盖县| 望谟县| 成都市| 手机| 三门县| 丰城市| 庆元县| 镇江市| 闽侯县| 沂源县| 乌兰察布市| 山东省| 徐汇区| 镇江市| 赤峰市| 萨嘎县| 夹江县| 蒲江县| 漳州市| 奇台县| 天全县| 南阳市| 新建县| 托里县| 凤庆县| 吉水县| 平山县| 宜丰县| 三原县| 武川县| 黄陵县| 南平市| 凤凰县| 凤翔县| 华池县| 吴堡县| 唐海县|