title: Why does Spring not inject @PersistenceContext entityManager when running on Tomcat vs standalone
body: <p>I am trying to use Spring to inject <code>@PersistenceContext entityManager</code> into my service. The following configuration works standalone but does not work when deploying on Tomcat. When deploying on Tomcat, the entityManager remains null. My JPA configs are in persistence.xml.</p>
  
  <pre><code>&lt;context:annotation-config /&gt;
  &lt;tx:annotation-driven/&gt;
  
  &lt;bean id="entityManagerFactory"
      class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"&gt;
      &lt;property name="staticMethod"&gt;
          &lt;value&gt;javax.persistence.Persistence.createEntityManagerFactory&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="arguments"&gt;
          &lt;list&gt;
              &lt;value&gt;persistenceUnit&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
    &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>What config changes do I need to make for injection to work on Tomcat 6 vs standalone?</p>
  
  <p>Edit: I am able to get the factory inside the service and get an entityManager from it, so persistence.xml settings seem to be working correctly.</p>
  
  <p><strong>Solution:</strong>
  I enabled Spring logging to find the issue -- a missing library. Apparently Spring fails quietly if the above <code>transactionManager</code> bean cannot be created. </p>