title: Cannot Inject Entity Manager in external Jar file
body: <p>i am in the process of developing a seperate java component which will be packaged as a jar and added to the parent project. the reason for making this as a component is because tomorrow i might have to remove that code and discard it. 
  The problem that i am facing is the standalone component,(jar file) which is being developed needs to query the database when someone calls its API. </p>
  
  <p>my parent project is setup using Spring + Hibernate + JPA. </p>
  
  <p>I am not able to inject the EntityManager from the parent project into the external Jar which is instantiated during the startup of the spring container. </p>
  
  <p>Is this conceptually correct? or is it possible to do it in this fashion?</p>
  
  <p>i want the jar file to just piggyback on the persistence.xml which is defined by the parent project and make use of the EntityManager which was loaded during startup. </p>
  
  <p><strong>EDIT</strong>
  The entityManager is injected through the LocalContainerEntityManagerFactoryBean in the main webapp in this fashion</p>
  
  <pre><code>&lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSourceWrapper" /&gt;
      &lt;property name="persistenceUnitName" value="LineManagement" /&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
              &lt;property name="generateDdl" value="false" /&gt;
              &lt;property name="showSql" value="false" /&gt;
              &lt;property name="databasePlatform"  value="${hibernate.dialect}" /&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
      &lt;property name="beanName" value="entityManager"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>The abstractDAO in the parent webapp is defined in the following manner, and the PersistenceContext annotation does give back the EntityManager and everything works fine.. </p>
  
  <pre><code>public abstract class AbstractDAO&lt;T extends LMEntity&gt; {
  
     @PersistenceContext(unitName = "LineManagement")
     protected EntityManager entityManager;
  
     @Autowired
     private DataSource dataSource;
  
     @Autowired
     private DAOSupport daoSupport;
  
     public void initHibernateStatistics() {
        HibernateStatistics.enableHibernateStatistics(entityManager);
     }
  </code></pre>
  
  <p>Below is the DAO in the jar file where i want the EntityManager to be injected so that it can use the one already provided </p>
  
  <p>This is the DAO in the jar file </p>
  
  <pre><code>@Repository(value = "retryDAO")
  public class RetryDAOImpl
    implements RetryDAO {
  
     @Autowired
     private EntityManager entityManager;
  
     @Transactional
     public void saveEvent(final IntegrationEvent event) {
        entityManager.merge(event);
     }
  </code></pre>
  
  <p>I tried the @Autowired annotation and it mentions that the entityManager bean isnt present. </p>