2012-05-14 2 views
1

2PC 커밋을 사용하려면 spring, oracle 및 jotm (tomcat)을 사용하고 있습니다. 다음은 스프링 구성입니다. 내가 JOTM 객체를 사용 getTransactionManager().getTransaction()를 호출 할 때 JOTM getTransactionManager(). getTransaction() return null

질문

<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> 

는 null을 반환한다.

Current cur = (Current) ContextHelper.getApplicationContext() 
        .getBean("txImpl"); 
      try { 
       log.error("cur : " cur.getTransactionManager().getTransaction()); 
     } catch (SystemException e) { 
      log.error(e.getMessage(), e); 
     } 

이 문제를 어떻게 해결할 수 있습니까?

답변

1

하나의 접근법은 이미 통합 된 TransactionManager가있는 Tomcat 인 Apache TomEE을 사용하는 것일 수 있습니다. TransactionManager와 UserTransaction을 Spring에 넘기위한 간단한 Spring 팩토리 빈을 작성하자.

모두 JNDI에서 조회 할 수 있습니다

  • java:comp/TransactionManager
  • java:comp/UserTransaction

그 공장은 바로 위의 설정에서 하나를 대체 할 것이다 :

<bean id="txImpl" class="org.foo.MyTransactionFactoryBean" /> 

비록를, 그것은 매우 가능성이 높습니다. Spring은 이미 요인을 가지고 있습니다. 이 bean을 통해 TransactionManager를 조회하기위한 bean.