title: Unsatisfied dependency through 'sessionFactory'; No qualifying bean of type 'org.hibernate.SessionFactory' available
body: <p>I am creating a spring-mvc and hibernate webapp. I am trying to test text read in the book by creating project (hence using xml config). This type of question is asked before but I can't get my project to work with answers offered. I get following error when I hit the end-point :</p>
  <pre><code>[WARNING] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'categoryController': Unsatisfied dependency expressed through field 'categoryService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'categoryServiceImpl': Unsatisfied dependency expressed through field 'categoryDAO'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'categoryDAOImpl': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.hibernate.SessionFactory' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=sessionFactory)}
  [ERROR] Context initialization failed
  </code></pre>
  <p>Here is @Configuration class</p>
  <pre><code>@Configuration
  @ComponentScan(basePackages= {&quot;pizzaml.rest&quot;, &quot;pizzaml.service&quot;, &quot;pizzaml.dao&quot;})
  @EnableWebMvc
  public class AppConfig {
      
      @Bean(name=&quot;sessionFactory&quot;)
      public SessionFactory sessionFactory( @Qualifier(&quot;dataSource&quot;) DataSource dataSource) throws MalformedURLException {
          LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
              
          sessionFactory.setDataSource(dataSource);
          sessionFactory.setConfigLocation(new FileUrlResource(&quot;/hibernate-cfg.xml&quot;));
          return sessionFactory.getObject();
      }
      
      @Bean(name=&quot;dataSource&quot;)
      public DataSource dataSource( @Value(&quot;{db.user}&quot;) String user, @Value(&quot;{db.pass}&quot;) String pass, @Value(&quot;{db.url}&quot;) String url, @Value(&quot;{db.driverclass}&quot;) String driverClass) {
          BasicDataSource datasource = new BasicDataSource();
          datasource.setDriverClassName(driverClass);
          datasource.setUsername(user);
          datasource.setPassword(pass);
          datasource.setUrl(url);
          
          return datasource;
      }
      
  }
  </code></pre>
  <p>Here is hibernate-cfg.xml</p>
  <pre><code>&lt;!DOCTYPE hibernate-configuration PUBLIC
          &quot;-//Hibernate/Hibernate Configuration DTD 3.0//EN&quot;
          &quot;http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd&quot;&gt;
          
      &lt;hibernate-configuration&gt;
          
          &lt;session-factory&gt;
              &lt;property name=&quot;dialect&quot;&gt;org.hibernate.dialect.MySQL5Dialect&lt;/property&gt;
              &lt;property name=&quot;show_sql&quot;&gt;true&lt;/property&gt;
              &lt;property name=&quot;hbm2ddl.auto&quot;&gt;update&lt;/property&gt;
              &lt;mapping resource=&quot;pizzaml/entity/Category.hbm.xml&quot;&gt;&lt;/mapping&gt;
          &lt;/session-factory&gt;
      
      &lt;/hibernate-configuration&gt;
  </code></pre>
  <p>DAO-</p>
  <pre><code>@Repository
  public class CategoryDAOImpl implements CategoryDAO {
      
      @Autowired
      @Qualifier(&quot;sessionFactory&quot;)
      SessionFactory sessionFactory;
  
      @Override
      public String addCategory(String categoryname) throws BusinessProcessException {
          
          Session session = sessionFactory.openSession();
          
          Query query = session.getNamedQuery(&quot;Category.byName&quot;);
          List&lt;Category&gt; list = query.list();
          
          if(Objects.nonNull(list) &amp;&amp; (!list.isEmpty()) )
              throw new BusinessProcessException(&quot;Category already exists!&quot;);
          
          Category category = new Category();
          category.setName(categoryname);
          
          session.save(category);
          
          session.flush();
          
          session.close();
          
          return AppCodes.SUCCESS;
      }
  
  }
  
  </code></pre>
  <p>pom.xml</p>
  <pre><code>  &lt;dependencies&gt;
    
      &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
          &lt;version&gt;5.2.10.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      
      &lt;!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
          &lt;version&gt;4.0.1&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      
      &lt;!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;5.4.22.Final&lt;/version&gt;
      &lt;/dependency&gt;
      
      &lt;!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
          &lt;artifactId&gt;commons-dbcp2&lt;/artifactId&gt;
          &lt;version&gt;2.8.0&lt;/version&gt;
      &lt;/dependency&gt;
      
      &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-orm --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
          &lt;version&gt;5.2.10.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;version&gt;8.0.22&lt;/version&gt;
      &lt;/dependency&gt;
      
      &lt;!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
          &lt;version&gt;2.11.3&lt;/version&gt;
      &lt;/dependency&gt;
      
      
    &lt;/dependencies&gt;
    
    &lt;build&gt;
      
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.8.1&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;source&gt;1.8&lt;/source&gt;
                  &lt;target&gt;1.8&lt;/target&gt;
              &lt;/configuration&gt;    
          &lt;/plugin&gt;
          
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.2.3&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;outputDirectory&gt;./target&lt;/outputDirectory&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt;
              &lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.2&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;port&gt;4500&lt;/port&gt;
                  &lt;path&gt;/&lt;/path&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          
      &lt;/plugins&gt;
  </code></pre>