ScarletLina 2012-04-20
一、环境
AtomikosTransactionsEssentials-3.7.2
下载地址:http://www.atomikos.com/Main/InstallingTransactionsEssentials
jar包引入
transactions-jdbc.jar(必须包)
transactions-jta.jar
transactions.jar
atomikos-util.jar
transactions-api.jar
拷贝
AtomikosTransactionsEssentials-3.7.2\examples\spring\jdbc
下面的
jta.properties到项目工程classpath根目录下(src下)
二.spring配置修改
参考AtomikosTransactionsEssentials-3.7.2\examples\spring\jdbc
的config.xml
有一个主意点:JtaTransactionManager
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManager"> <ref bean="atomikosTransactionManager" /> </property> <property name="userTransaction"> <ref bean="atomikosUserTransaction" /> </property> <property name="allowCustomIsolationLevels" value="true"/> <!-必须设置,否则程序出现异常 JtaTransactionManager does not support custom isolation levels by default --> </bean>
另外:
3.7.2已经没有SimpleDataSource这个类了
加了个AtomikosDataSourceBean这个类
关于这个问题的解决:
每当我启动tomcat时,控制台就平凡打印如下警告,不影响系统运行。
WARNatomikos:107-Localheuristicterminationofcoordinatorcom.atomikos.spring.jdbc.tm0050000015withstateHEUR_HAZARD
2011/04/2913:55:45724WARNatomikos:107-Localheuristicterminationofcoordinatorcom.atomikos.spring.jdbc.tm0050000015withstateHEUR_HAZARD
2011/04/2913:55:45878WARNatomikos:107-Localheuristicterminationofcoordinatorcom.atomikos.spring.jdbc.tm0050000015withstateHEUR_HAZARD
2011/04/2913:55:4630WARNatomikos:107-Localheuristicterminationofcoordinatorcom.atomikos.spring.jdbc.tm0050000015withstateHEUR_HAZARD
修改jta.properties文件应该是关掉日志
com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory com.atomikos.icatch.automatic_resource_registration = true com.atomikos.icatch.enable_logging = false
关于JBPM报的多个sessionFactory警告的处理
参考:http://hi.baidu.com/btb368/blog/item/bc419c51e1b8007b8435246a.html
MultipleSpringbeansfoundfortypeinterfaceorg.hibernate.SessionFactoryreturningthefirstone
2011-07-0511:08
在OECP平台中,我们支持多数据源的配置,以支持对平台数据库和业务组件数据库的操作,但是在将jbpm4.4整合进来做工作流引擎的时候,却出现了问题。
采用官方的解决方案,在单数据源下没有问题,但是在多数据源下,我们采用jotm的jta事务,当在一个事务之内既有操作平台的服务,又有操作jbpm的服务时,控制台上打印一下警告和错误。更为奇怪的是,如果在一个事务里先执行jbpm的数据库操作,在执行其他的数据操作,没有问题,反过来却不行,一头雾水啊。难道jbpm搞不清楚是哪个sessionfactory了。经过Google和长时间的分析,解决了该问题,现把方案分享一下。
问题:
MultipleSpringbeansfoundfortypeinterfaceorg.hibernate.SessionFactoryreturningthefirstonefound
java.sql.SQLException:CannotgetconnectionforURLjdbc:oracle:thin**调用中无效的参数
一、扩展SpringHelper,添加setSessionFactory,指定sessionfactory注入
packagecom.abc.onewaveinc.core.common;
importorg.hibernate.SessionFactory;
importorg.jbpm.api.ProcessEngine;
importorg.jbpm.pvm.internal.cfg.ConfigurationImpl;
importorg.jbpm.pvm.internal.processengine.SpringHelper;
publicclassProcessEngineFactoryBeanextendsSpringHelper{
privateSessionFactorysessionFactory;
publicvoidsetSessionFactory(SessionFactorysessionFactory){
this.sessionFactory=sessionFactory;
}
publicSessionFactorygetSessionFactory(){
returnsessionFactory;
}
publicProcessEnginecreateProcessEngine(){
ProcessEngineprocessEngine=newConfigurationImpl().springInitiated(
applicationContext).setResource(jbpmCfg)
.setHibernateSessionFactory(sessionFactory)
.buildProcessEngine();
returnprocessEngine;
}
}
<!--jbpm配置cn.oecp.jbpm4.cfg.pvm.ProcessEngineFactoryBean上面已经定义-->
<beanid="springHelper"class="com.onewaveinc.core.common.ProcessEngineFactoryBean">
<propertyname="jbpmCfg">
<value>jbpm.cfg.xml</value>
</property>
<propertyname="sessionFactory">
<refbean="sessionFactory"/>
</property>
</bean>
二、其他配置省略,修改了jbpm.tx.spring.cfg.xml中spring事务拦截方式,这一步很关键,保证在一个事务管理器内
<?xmlversion="1.0"encoding="UTF-8"?>
<jbpm-configurationspring="enabled">
<process-engine-context>
<command-servicename="newTxRequiredCommandService">
<retry-interceptor/>
<environment-interceptorpolicy="requiresNew"/>
<spring-transaction-interceptor
policy="requiresNew"transaction-manager="hibernateTransactionManager"/>
</command-service>
<!--DefaultcommandservicehasaSpringtransactioninterceptor-->
<command-servicename="txRequiredCommandService">
<retry-interceptor/>
<environment-interceptorpolicy="requiresNew"/>
<spring-transaction-interceptor
current="hibernateTransactionManager"/>
</command-service>
</process-engine-context>
<transaction-context>
<transactiontype="spring"/>
<repository-session></repository-session>
<hibernate-sessioncurrent="true"/>
</transaction-context>
</jbpm-configuration>
http://www.oecp.cn/hi/yongtree/blog/2562
参考文档:
Spring+iBatis+Atomikos实现JTA事务
http://www.chineselinuxuniversity.net/articles/39426.shtml
spring+atomikos+JTA完整例子
http://www.cnblogs.com/huangjingzhou/articles/2012011.html
SpringJTA应用JOTM&AtomikosIIIAtomikos
JTA集成JOTM或Atomikos配置分布式事务(Tomcat应用服务器)
http://kb.cnblogs.com/a/2012014/