title: Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
body: <p>Error creating bean with name 'trangchuController': 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)}</p>
  
  <p>IoC.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:aop="http://www.springframework.org/schema/aop"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx.xsd
      http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop.xsd
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-4.3.xsd
      "&gt;
  
  &lt;context:component-scan base-package="tuan.controller"/&gt;
  &lt;context:component-scan base-package="tuan.entity"/&gt;
  &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
  destroy-method="close"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
      &lt;property name="url" value="jdbc:mysql://localhost/db_thoitrang" /&gt;
      &lt;property name="username" value="root" /&gt;
      &lt;property name="password" value="" /&gt;
  &lt;/bean&gt;
  
  
  &lt;bean id="sessionFactory" 
  class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;property name="packagesToScan" value="tuan.entity"&gt;&lt;/property&gt;
      &lt;property name="hibernateProperties"&gt;
          &lt;value&gt;
              hibernate.dialect=org.hibernate.dialect.MySQLDialect
          &lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager" 
  class="org.springframework.orm.hibernate5.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
  &lt;/bean&gt;
  
  &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>controller</strong></p>
  
  <pre><code>package tuan.controller;
  
  import java.util.List;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.transaction.annotation.Transactional;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.RequestMapping;
  
  import tuan.entity.NhanVien;
  
  @Controller
  @RequestMapping("/")
  public class trangchuController {
  
  @Autowired
  SessionFactory sessionFactory;
  
  @GetMapping
  @Transactional
     public String index() {
          Session session = sessionFactory.getCurrentSession();
          String sql = "from nhanvien";
          List&lt;NhanVien&gt; list = session.createQuery(sql).getResultList();
  
          for(NhanVien nv: list) {
               System.out.println(nv.getTenNhanVien()+" : "+nv.getTuoi());
          }
          return "trangchu";
      }
  }   
  </code></pre>
  
  <p><strong>NhanVien</strong></p>
  
  <p>`package tuan.entity;</p>
  
  <p>import javax.persistence.Entity;
  import javax.persistence.Id;</p>
  
  <pre><code> @Entity(name="nhanvien")
   public class NhanVien {
       @Id
       int idNhanVien;
       String TenNhanVien;
       int Tuoi;
       public int getId() {
           return idNhanVien;
       }
       public void setId(int idNhanVien) {
           this.idNhanVien = idNhanVien;
        }
       public String getTenNhanVien() {
         return TenNhanVien;
       }
       public void setTenNhanVien(String tenNhanVien) {
            TenNhanVien = tenNhanVien;
       }
       public int getTuoi() {
            return Tuoi;
       }
        public void setTuoi(int tuoi) {
           Tuoi = tuoi;
        }
   }
  </code></pre>