title: JNDI initial context for JtaTransactionManager using Spring and Glassfish
body: <p>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 <code>JtaTransactionManager</code> instance. My Spring bean configuration for <code>JtaTransactionManager</code> is set up as follows:</p>
  
  <pre><code>&lt;tx:annotation-driven transaction-manager="jtaTransactionManager"/&gt;
  
  &lt;bean id="jtaTransactionManager"
      class="org.springframework.transaction.jta.JtaTransactionManager"&gt;
      &lt;property name="transactionManagerName" value="java:comp/TransactionManager"/&gt;
      &lt;property name="userTransactionName" value="java:comp/UserTransaction"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>But when I run the program, it reported errors:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>which is associated with Non-initialized JNDI context. So I added a resource file <code>jndi.properties</code> which adds the missing initial context reported above:</p>
  
  <pre><code>java.naming.factory.initial=???
  </code></pre>
  
  <p>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 <a href="http://docs.oracle.com/cd/E19798-01/821-1752/gaxit/index.html" rel="noreferrer">official document</a> only says:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>So how should I set up the JNDI initial factory for JTA Transaction Manager in <code>jndi.properties</code> file so that both <code>TransactionManager</code> and <code>UserTransaction</code> can be injected into my <code>jtaTransactionManager</code> bean by JNDI lookup? Thanks.</p>