title: No bean named 'persistence-unit' is defined
body: <p>I'm developing a spring jpa hibernate application and i have the following exception:</p>
  
  <pre><code>Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addressDAO': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'persistence-unit' is defined
  at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:357)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1219)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:751)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
  at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:139)
  at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:83)
  at ma.jobcenter.dao.Main.main(Main.java:21)
  </code></pre>
  
  <p>It says that no bean named 'persistence-unit' was found.</p>
  
  <p>Here is my persistence.xml:</p>
  
  <pre><code>&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
           version="2.0"&gt;
  
  &lt;persistence-unit name="persistence-unit" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;class&gt;ma.jobcenter.domain.Address&lt;/class&gt;
      &lt;class&gt;ma.jobcenter.domain.Candidate&lt;/class&gt;
      &lt;class&gt;ma.jobcenter.domain.RegistredUser&lt;/class&gt;
      &lt;properties&gt;
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/&gt;
          &lt;property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/&gt;
          &lt;property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/test-db"/&gt;
          &lt;property name="hibernate.connection.username" value="postgres"/&gt;
          &lt;property name="hibernate.connection.password" value="root"/&gt;
          &lt;property name="show_sql" value="false"/&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here is my AbstractDAO that every DAO class is inheriting from:</p>
  
  <pre><code>public abstract class AbstractDAO {
  
  @PersistenceContext(unitName = "persistence-unit")
  protected EntityManager entityManager;
  
  public AbstractDAO() {
      super();
  }
  
  public EntityManager getEntityManager() {
      return entityManager;
  }
  
  public void setEntityManager(EntityManager entityManager) {
      this.entityManager = entityManager;
  }
  }
  </code></pre>
  
  <p>And this is my spring application-context.xml:</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:context="http://www.springframework.org/schema/context"
     xmlns:util="http://www.springframework.org/schema/util"
     xmlns:mvc="http://www.springframework.org/schema/mvc"
     xmlns:tx="http://www.springframework.org/schema/tx"
     xsi:schemaLocation="http://www.springframework.org/schema/mvc
                         http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
                         http://www.springframework.org/schema/beans
                         http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
                         http://www.springframework.org/schema/tx
                         http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
                         http://www.springframework.org/schema/util
                         http://www.springframework.org/schema/util/spring-util-4.3.xsd
                         http://www.springframework.org/schema/context
                         http://www.springframework.org/schema/context/spring-context-4.3.xsd"&gt;
  
  &lt;!--  tell spring where to find the beans --&gt;
  &lt;context:component-scan base-package="ma.jobcenter.dao" /&gt;
  &lt;context:component-scan base-package="ma.jobcenter.service" /&gt;
  &lt;!--  tell spring to use annotation based congfigurations --&gt;
  &lt;context:annotation-config/&gt;
  
  &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"&gt;
      &lt;!-- access --&gt;
      &lt;property name="driverClass" value="org.postgresql.Driver" /&gt;
      &lt;property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/jobcenter-test-db" /&gt;
      &lt;property name="user" value="postgres" /&gt;
      &lt;property name="password" value="root" /&gt;
  
      &lt;!-- pool sizing --&gt;
      &lt;property name="initialPoolSize" value="10" /&gt;
      &lt;property name="minPoolSize" value="10" /&gt;
      &lt;property name="maxPoolSize" value="50" /&gt;
      &lt;property name="acquireIncrement" value="5" /&gt;
      &lt;property name="maxStatements" value="100" /&gt;
  
      &lt;!-- retries --&gt;
      &lt;property name="acquireRetryAttempts" value="20" /&gt;
      &lt;property name="acquireRetryDelay" value="1000" /&gt; &lt;!-- 1s --&gt;
      &lt;property name="breakAfterAcquireFailure" value="false" /&gt;
  
      &lt;!-- refreshing connections --&gt;
      &lt;property name="maxIdleTime" value="300" /&gt; &lt;!-- 5min --&gt;
      &lt;property name="maxConnectionAge" value="300" /&gt; &lt;!-- 1h --&gt;
  
      &lt;!-- timeouts and testing --&gt;
      &lt;property name="testConnectionOnCheckout" value="false" /&gt;
      &lt;property name="testConnectionOnCheckin" value="false" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="persistenceXmlLocation" value="classpath:persistence.xml" /&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;property name="packagesToScan" value="ma.jobcenter.domain.*" /&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
              &lt;property name="showSql" value="false" /&gt;
              &lt;property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" /&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  
  &lt;bean id="addressDAO" class="ma.jobcenter.dao.AddressDAOImpl"/&gt;
  &lt;bean id="candidateDAO" class="ma.jobcenter.dao.CandidateDAOImpl"/&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>The application is runing on Tomcat.
  I really don't understand this exception and i didn't found any answer.
  Thanks in advance.</p>