[英]JOTM getTransactionManager().getTransaction() return null
I'm using spring, oracle and jotm (in tomcat) to use 2PC commit. 我正在使用spring,oracle和jotm(在tomcat中)使用2PC提交。 Below is the spring configuration. 以下是弹簧配置。
<aop:config>
<aop:pointcut id="defaultOperation"
expression="execution(* jatis.avantrade.foundation.model.engine.*.*(..))" />
<aop:advisor advice-ref="defaultTrxAdvice" pointcut-ref="defaultOperation" />
</aop:config>
<tx:advice id="defaultTrxAdvice" transaction-manager="trxManager">
<tx:attributes>
<tx:method name="check*" read-only="true" />
<tx:method name="get*" read-only="true" />
<tx:method name="is*" read-only="true" />
<tx:method name="load*" read-only="true" />
<tx:method name="select*" read-only="true" />
<tx:method name="count*" read-only="true" />
<tx:method name="search*" read-only="true" />
<tx:method name="list*" read-only="true" />
<tx:method name="*" rollback-for="Throwable" />
</tx:attributes>
</tx:advice>
<bean id="txImpl" class="org.springframework.transaction.jta.JotmFactoryBean" />
<bean id="trxManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="txImpl" />
<property name="userTransaction" ref="txImpl" />
</bean>
The questions is when I call getTransactionManager().getTransaction()
using JOTM object, it returns null. 问题是,当我使用JOTM对象调用getTransactionManager().getTransaction()
,它返回null。
Current cur = (Current) ContextHelper.getApplicationContext()
.getBean("txImpl");
try {
log.error("cur : " cur.getTransactionManager().getTransaction());
} catch (SystemException e) {
log.error(e.getMessage(), e);
}
How can I fix this issue? 如何解决此问题?
One approach might be to use Apache TomEE which is Tomcat with the TransactionManager already integrated. 一种方法可能是使用Apache TomEE ,它是已经集成了TransactionManager的Tomcat。 The write a simple Spring factory bean to hand Spring the TransactionManager and UserTransaction. 编写一个简单的Spring工厂bean来传递Spring TransactionManager和UserTransaction。
Both can be looked up from JNDI: 两者都可以从JNDI查找:
java:comp/TransactionManager
java:comp/UserTransaction
That factory would just replace the one from the above config: 该工厂将替换上面配置中的一个:
<bean id="txImpl" class="org.foo.MyTransactionFactoryBean" />
Though, it's very likely Spring already has a factory bean for looking up the TransactionManager via these names. 虽然,Spring很可能已经有了一个工厂bean,可以通过这些名称查找TransactionManager。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.