title: Error creating bean with name 'usersDao': Unsatisfied dependency expressed through field 'sessionFactory'
body: <p>I know that they are a lot of other questions like mine, but I don't seem to find the answer that I need. I'm new to Spring and Hibernate, so I don't understand much yet. I'm using Jetty Runner. Anyway, I was going to start to use Hibernate in my application and I had this error:</p>
  
  <pre><code>2018-05-03 15:37:03 ERROR ContextLoader:316 - Context initialization failed
  org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'usersDao': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.orm.hibernate5.LocalSessionFactoryBean' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587)
  at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1344)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)
  at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
  at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:409)
  at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291)
  at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
  at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:890)
  at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:532)
  at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:853)
  at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:344)
  at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1501)
  at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1463)
  at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:785)
  at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:261)
  at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
  at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
  at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
  at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113)
  at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
  at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:167)
  at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
  at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
  at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113)
  at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
  at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
  at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
  at org.eclipse.jetty.server.Server.start(Server.java:452)
  at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
  at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
  at org.eclipse.jetty.server.Server.doStart(Server.java:419)
  at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
  at org.eclipse.jetty.runner.Runner.run(Runner.java:518)
  at org.eclipse.jetty.runner.Runner.main(Runner.java:559)
  Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.orm.hibernate5.LocalSessionFactoryBean' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1509)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584)
  ... 42 more
  2018-05-03 15:37:03 WARN  WebAppContext:554 - Failed startup of context o.e.j.w.WebAppContext@b97c004{/DonaRegistration,file:///C:/Users/Asuka/Desktop/DonaRegistration/WebContent/,UNAVAILABLE}{file:///C:/Users/Asuka/Desktop/DonaRegistration/WebContent/}
  org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'usersDao': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.orm.hibernate5.LocalSessionFactoryBean' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587)
  at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1344)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)
  at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
  at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:409)
  at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291)
  at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
  at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:890)
  at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:532)
  at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:853)
  at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:344)
  at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1501)
  at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1463)
  at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:785)
  at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:261)
  at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
  at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
  at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
  at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113)
  at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
  at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:167)
  at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
  at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
  at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113)
  at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
  at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
  at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
  at org.eclipse.jetty.server.Server.start(Server.java:452)
  at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
  at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
  at org.eclipse.jetty.server.Server.doStart(Server.java:419)
  at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
  at org.eclipse.jetty.runner.Runner.run(Runner.java:518)
  at org.eclipse.jetty.runner.Runner.main(Runner.java:559)
  Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.orm.hibernate5.LocalSessionFactoryBean' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1509)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584)
  ... 42 more
  </code></pre>
  
  <p>I'm not sure what is happening, can someone help me please?</p>
  
  <p>This is my code: </p>
  
  <p>UsersDao</p>
  
  <pre><code>package com.winwel.spring.web.dao;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.jdbc.core.BeanPropertyRowMapper;
  import org.springframework.jdbc.core.RowMapper;
  import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
  import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
  import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
  import org.springframework.security.access.annotation.Secured;
  import org.springframework.security.crypto.password.PasswordEncoder;
  import org.springframework.stereotype.Component;
  import org.springframework.transaction.annotation.Transactional;
  import javax.sql.DataSource;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.util.List;
  
  @Transactional
  @Component("usersDao")
  public class UsersDao {
  
      private NamedParameterJdbcTemplate jdbc;
  
      @Autowired
      private PasswordEncoder passwordEncoder;
  
      //Only when I add this I get my error
      **@Autowired
      private LocalSessionFactoryBean sessionFactory;**
  
      @Autowired
      public void setDataSource(DataSource jdbc) {
          this.jdbc = new NamedParameterJdbcTemplate(jdbc);
      }
  </code></pre>
  
  <p>dao-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:jee="http://www.springframework.org/schema/jee"
         xmlns:tx="http://www.springframework.org/schema/tx"
         xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
         http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"&gt;
  
      &lt;context:annotation-config/&gt;
      &lt;context:component-scan base-package="com.winwel.spring.web.dao"/&gt;
  
  
      &lt;beans profile="production"&gt;
          &lt;jee:jndi-lookup jndi-name="jdbc/spring" id="dataSource" expected-type="javax.sql.DataSource"/&gt;
  
          &lt;bean autowire-candidate="true" id="sessionFactory" class="org.springframework.orm.hibernate5.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.MySQL5Dialect&lt;/prop&gt;
                  &lt;/props&gt;
              &lt;/property&gt;
              &lt;property name="packagesToScan"&gt;
                  &lt;list&gt;
                      &lt;value&gt;com.winwel.spring.web.dao&lt;/value&gt;
                  &lt;/list&gt;
              &lt;/property&gt;
          &lt;/bean&gt;
  
          &lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
              &lt;property name="dataSource" ref="dataSource"/&gt;
          &lt;/bean&gt;
          &lt;tx:annotation-driven/&gt;
  
      &lt;/beans&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>I'm using Spring 5.0.4 and Hibernate 5.2.13 and as far as I know they are compatible.</p>
  
  <p>I've tried adding <code>@Qualifier</code>, with/without <code>"autowire-candidate=true"</code> as well as <code>@Autowired(required= true)</code>, I've checked my packages and they look fine. I really don't know what is happening.</p>
  
  <p>If you need anything else feel free to ask.</p>