title: Spring JTA TransactionManager config: Supporting both Tomcat and JBoss
body: <p>I have a web application using JPA and JTA with Spring. I would like to support both JBoss and Tomcat. When running on JBoss, I'd like to use JBoss' own TransactionManager, and when running on Tomcat, I'd like to use JOTM.</p>
  
  <p>I have both scenarios working, but I now find that I seem to need two separate Spring configurations for the two cases. With JOTM, I need to use Spring's <code>JotmFactoryBean</code>:</p>
  
  <pre><code>&lt;bean id="transactionManager" 
   class="org.springframework.transaction.jta.JtaTransactionManager"&gt;
      &lt;property name="userTransaction"&gt;
          &lt;bean class="org.springframework.transaction.jta.JotmFactoryBean"/&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>In JBoss, though, I just need to fetch "TransactionManager" from JNDI:</p>
  
  <pre><code>&lt;bean id="transactionManager" 
   class="org.springframework.transaction.jta.JtaTransactionManager"&gt;
      &lt;property name="transactionManager"&gt;
          &lt;bean class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
               &lt;property name="resourceRef" value="true" /&gt;
               &lt;property name="jndiName" value="TransactionManager" /&gt;
               &lt;property name="expectedType" 
                 value="javax.transaction.TransactionManager" /&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Is there a way to configure this so that the appropriate TransactionManager - JBoss or JOTM - is used, without the need for two different configuration files?</p>