I want to use JTA Transaction Manager for my application. I'm using Spring and Glassfish. I want to use JNDI lookup to get the JtaTransactionManager
instance. My Spring bean configuration for JtaTransactionManager
is set up as follows:
<tx:annotation-driven transaction-manager="jtaTransactionManager"/>
<bean id="jtaTransactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManagerName" value="java:comp/TransactionManager"/>
<property name="userTransactionName" value="java:comp/UserTransaction"/>
</bean>
But when I run the program, it reported errors:
Caused by: org.springframework.transaction.TransactionSystemException: JTA UserTransaction is not available at JNDI location [java:comp/UserTransaction]; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
which is associated with Non-initialized JNDI context. So I added a resource file jndi.properties
which adds the missing initial context reported above:
java.naming.factory.initial=???
But the question is: What should I put in the above JNDI initial context field to be able get Glassfish transaction manager via JNDI lookup? I searched a number of sources but didn't find this piece of information. The official document only says:
To access a UserTransaction instance, you can either look it up using the java:comp/UserTransaction JNDI name or inject it using the @Resource annotation.
So how should I set up the JNDI initial factory for JTA Transaction Manager in jndi.properties
file so that both TransactionManager
and UserTransaction
can be injected into my jtaTransactionManager
bean by JNDI lookup? Thanks.
JtaTransactionManager
use<tx:jta-transaction-manager />
that does detection on which server you are running and does some environment specific lookups and configuration. – ChervilNo JTA UserTransaction available - specify either 'userTransaction' or 'userTransactionName' or 'transactionManager' or 'transactionManagerName'
. – Monarchaljndi.properties
file in order to detect the transaction manager? – Monarchal<tx:jta-transaction-manager />
when using a local transactionmanager. If you are using a remote JNDI you will have to add that file. But I assume you are deploying on the same glassfish as you want to use for transactions. – Chervil