title: Issues while running JUnit on maven project using Spring JTA
body: <p>I have a Spring + Hibernate project deployed on JBoss 5. It was using Ant earlier and recently I have modified the project structure to use Maven 2. But all the code and config files are the same.</p>
  
  <p>I am using Spring JTA for transaction management in my project. I am able to perfecly buid the project and deploy it on JBoss. But when I try to execute the JUnit tests it gives me the following error:</p>
  
  <pre><code>java.lang.IllegalStateException: No JTA UserTransaction available - specify either 'userTransaction' or 'userTransactionName' or 'transactionManager' or 'transactionManagerName'
      at org.springframework.transaction.jta.JtaTransactionManager.checkUserTransactionAndTransactionManager(JtaTransactionManager.java:473)
      at org.springframework.transaction.jta.JtaTransactionManager.afterPropertiesSet(JtaTransactionManager.java:413)
  </code></pre>
  
  <p>The wierd thing is that this was working perfeclty fine when I was using Ant. It started coming after the migration to maven.</p>
  
  <p>This is the entry in spring-jpa-conf.xml file:</p>
  
  <pre><code>&lt;bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" &gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>And this is the Junit code:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations = { "classpath:spring-conf.xml" })
  @Transactional(value = "transactionManager")
  public abstract class LocalUsersTestBase {
  
      @PersistenceContext(unitName="books-lemf")
      protected EntityManager entityManager;
  
      protected void getUsersDetails(List&lt;Users&gt; out) {
              ..........
  }
  </code></pre>
  
  <p>I also tried to add a property in the config file entry as shown here:</p>
  
  <pre><code>&lt;bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" &gt;
      &lt;property name="userTransactionName" value="java:/TransactionManager"&gt;&lt;/property&gt;  
      &lt;/bean&gt;
  </code></pre>
  
  <p>But it gives the error:</p>
  
  <pre><code>Caused by: org.springframework.transaction.TransactionSystemException: JTA UserTransaction is not available at JNDI location [java:/TransactionManager]; 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
      at org.springframework.transaction.jta.JtaTransactionManager.lookupUserTransaction(JtaTransactionManager.java:548)
      at org.springframework.transaction.jta.JtaTransactionManager.initUserTransactionAndTransactionManager(JtaTransactionManager.java:425)
      at org.springframework.transaction.jta.JtaTransactionManager.afterPropertiesSet(JtaTransactionManager.java:412)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1400)
      ... 37 more
  Caused by: 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
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
      at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
  </code></pre>
  
  <p>Please help.</p>
  
  <p>Thanks!!</p>
  
  <p>This is my complete spring config file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:jee="http://www.springframework.org/schema/jee"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
                          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" &gt;
          &lt;/bean&gt;
  
      &lt;jee:jndi-lookup id="books-pu" 
          jndi-name="java:/books-emf" 
          cache="true"
          lookup-on-startup="false"
          proxy-interface="javax.persistence.EntityManagerFactory"
      /&gt;
  
      &lt;jee:jndi-lookup id="booksDataSource" jndi-name="java:/books-ds"/&gt;
  
  
  &lt;/beans&gt;
  </code></pre>