title: No matching bean of type [org.hibernate.SessionFactory] found for dependency
body: <p>I'm a beginner in the Spring MVC. I encounter a problem "<strong>No matching bean of type [org.hibernate.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.</strong>" and spend a lot time.</p>
  
  <p>I used maven build management. My project has a project that consists 2 module : springcore (jar) and springmvc (web app). And springmvc (web app) has been dependency spring core. In module spring core, i defined all package such as dom, dao, service and their implementation and i also defined applicationContext.xml in src/main/resources following : </p>
  
  <p>applicationContext.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:tx="http://www.springframework.org/schema/tx" 
         xsi:schemaLocation="http://www.springframework.org/schema/beans 
             http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
             http://www.springframework.org/schema/tx 
             http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
             http://www.springframework.org/schema/context
             http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
      &lt;!-- Activates scanning of @Autowired --&gt;
      &lt;context:annotation-config /&gt;
  
      &lt;context:component-scan base-package="com.netvn" /&gt; 
  
      &lt;bean id="propertyConfigurer"
           class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
           p:location="classpath:jdbc" /&gt;
  
      &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
              destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
              p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"                    p:password="${jdbc.password}" /&gt;
  
      &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
              &lt;property name="dataSource" ref="dataSource" /&gt;
              &lt;property name="annotatedClasses"&gt;
                      &lt;list&gt;
                           &lt;value&gt;com.netvn.dom.Contact&lt;/value&gt;
                      &lt;/list&gt;
              &lt;/property&gt;
              &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
              &lt;prop key="hibernate.max_fetch_depth"&gt;3&lt;/prop&gt;
              &lt;prop key="hibernate.jdbc.fetch_size"&gt;50&lt;/prop&gt;
              &lt;prop key="hibernate.jdbc.batch_size"&gt;10&lt;/prop&gt;
              &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
      &lt;bean id="transactionManager"
              class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
           &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>ContactDaoImpl.java</p>
  
  <pre><code>@Repository
  public class ContactDaoImpl implements ContactDao {
      private Log log = LogFactory.getLog(ContactDaoImpl.class);
  
      @Autowired
      private SessionFactory sessionFactory;
  
      public List&lt;Contact&gt; listContact() {
          Session session = sessionFactory.getCurrentSession();
          Query q = session.createQuery("select g from Contact g order by id desc");
          List&lt;Contact&gt; contactList= q.list(); 
          return contactList; 
      }
  }
  </code></pre>
  
  <p>ContactServiceImpl.java </p>
  
  <pre><code>@Service
  @Transactional
  public class ContactServiceImpl implements ContactService {
  
      @Autowired
      private ContactDao contactDao;
  
      @Transactional(propagation=Propagation.REQUIRED)
      public List&lt;Contact&gt; listContact(){
          return contactDao.listContact();
      }
  }
  </code></pre>
  
  <p>In springmvc (web app), i defined web.xml and dispatcher-servlet.xml</p>
  
  <p>dispatcher-servlet.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:mvc="http://www.springframework.org/schema/mvc"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
                   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                   http://www.springframework.org/schema/mvc 
                   http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                   http://www.springframework.org/schema/context
                   http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
      &lt;context:annotation-config /&gt;
  
      &lt;mvc:annotation-driven /&gt;
      &lt;context:component-scan base-package="com.netvn.dao" /&gt;
      &lt;context:component-scan base-package="com.netvn.service" /&gt;
      &lt;context:component-scan base-package="com.netvn.controller" /&gt;
  
      &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
              p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" /&gt;
  
   &lt;/beans&gt;
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  version="3.0"&gt;
      &lt;context-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;
                   classpath*:*.xml
               &lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;servlet&gt;
              &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
              &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
              &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
              &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
              &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;listener&gt;
            &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt; 
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Here is my problem when i try to run it in Tomcat 6.0 server <br /></p>
  
  <pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.netvn.dao.impl.ContactDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.hibernate.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:502)
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
      ... 86 more
  Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.hibernate.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
  </code></pre>
  
  <p>Can someone tell me, what is the reason SessionFactory can't be created by Web Application Context or any problem when i configured SessionFactory. </p>
  
  <p>Any supporting will be appreciated.</p>