title: Unable to autowire SessionFactory
body: <p>I have a little Spring app and I'm attempting to add Hibernate to it. Here is my servlet config:</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:mvc="http://www.springframework.org/schema/mvc"
         xmlns:p="http://www.springframework.org/schema/p"
         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.2.xsd
             http://www.springframework.org/schema/context
             http://www.springframework.org/schema/context/spring-context-3.2.xsd
             http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
             "&gt;
  
      &lt;context:component-scan base-package="net.vivin"/&gt;
      &lt;mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" /&gt;
      &lt;tx:annotation-driven /&gt;
  
      &lt;!-- View naming conventions --&gt;
      &lt;bean id="viewNameTranslator" class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator"/&gt;
  
      &lt;!-- Controller and action naming conventions --&gt;
      &lt;bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/&gt;
  
      &lt;!-- Resolver for JSP views --&gt;
      &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /&gt;
          &lt;property name="prefix" value="/WEB-INF/jsp/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"&gt;
          &lt;!-- Turn off working out content type based on URL file extension, should fall back to looking at the Accept headers --&gt;
          &lt;property name="favorPathExtension" value="false" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="multipartResolver"  class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/&gt;
  
      &lt;bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" /&gt;
  
      &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
          &lt;property name="driverClassName" value="org.postgresql.Driver" /&gt;
          &lt;property name="url" value="jdbc:postgresql://localhost:5433/test" /&gt;
          &lt;property name="username" value="test" /&gt;
          &lt;property name="password" value="test" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.PostgreSQL82Dialect&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.use_sql_comments"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.hbm2ddl.auto"&gt;create-drop&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
          &lt;property name="packagesToScan" value="net.vivin" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="transactionManager"
            class="org.springframework.orm.hibernate4.HibernateTransactionManager"
            p:sessionFactory-ref="sessionFactory"&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>I have a <code>DatabaseUserDAO</code> and a <code>DatabaseRoleDAO</code> class both of which implement <code>UserDAO</code> and <code>RoleDAO</code> respectively. Both implementations have been annotated with <code>@Repository</code> as well. I have not implemented any service classes; I just wanted to get up and running to make sure that my configuration is correct.</p>
  
  <p>I cannot figure out what is wrong. When the app starts up, I get the following stacktrace:</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'databaseUserDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory net.vivin.myapp.dao.DatabaseUserDAO.sessionFactory; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying 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)}
  </code></pre>
  
  <p>I know that I have defined the session factory in my spring config. Why isn't Spring seeing it then?</p>