title: JPA No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined
body: <p>I have a JPA/spring/hibernate application deployed on Tomcat 8. But when the tomcat server startup i can see this warning message "No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined". Help would be appreciated because i have no idea about the configuration error.</p>
  
  <p>persistence.xml</p>
  
  <pre><code>&lt;persistence-unit name="persistenceUnit"
      transaction-type="RESOURCE_LOCAL"&gt;
  ...
  </code></pre>
  
  <p>spring context files are defined into several files for reusability</p>
  
  <p>context-ds.xml</p>
  
  <pre><code>&lt;bean id="entityManager" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="dataSource" ref="datasource" /&gt;
      &lt;property name="persistenceUnitName" value="persistenceUnit" /&gt;
  &lt;/bean&gt;
  &lt;bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManager" /&gt;
  &lt;/bean&gt;
  &lt;bean id="datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource" &gt;
  ...
  </code></pre>
  
  <p>context-config.xml</p>
  
  <pre><code>&lt;context:annotation-config /&gt;
  &lt;context:component-scan base-package="com.app" /&gt;
  &lt;jpa:repositories base-package="com.app" /&gt;
  &lt;tx:annotation-driven transaction-manager="txManager"
      order="200" /&gt;
  </code></pre>
  
  <p>and web.xml</p>
  
  <pre><code>&lt;context-param&gt;
    &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
    &lt;param-value&gt;/WEB-INF/context-config.xml, /WEB-INF/context-ds.xml, /WEB-INF/context-dao.xml&lt;/param-value&gt;
  &lt;/context-param&gt;
  </code></pre>
  
  <p>and DAO abstract class defines the PersistenceContext annotation</p>
  
  <pre><code>@PersistenceContext
  protected EntityManager entityManager;
  </code></pre>
  
  <p>Real message</p>
  
  <pre><code>11:45:18.710 [localhost-startStop-1] WARN  AbstractBeanFactory.getTypeForFactoryBean - Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDAO' defined in ServletContext resource [/WEB-INF/context-dao.xml]: Cannot create inner bean 'genericDao$child#632cb33' of type [com.app.dao.GenericDaoImpl] while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'genericDao$child#632cb33': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined
  </code></pre>
  
  <p>if i declare PersistenceContext like this, i have the message No bean named 'persistenceUnit' is defined</p>
  
  <pre><code>@PersistenceContext(unitName="persistenceUnit")
  protected EntityManager entityManager;
  </code></pre>