title: required a bean of type 'org.hibernate.SessionFactory' that could not be found
body: <p><strong>I am getting following error whenever started application spring boot.</strong></p>
  
  <hr>
  
  <p>APPLICATION FAILED TO START</p>
  
  <hr>
  
  <p>Description:</p>
  
  <p>Field session in com.base.model.AbstractDao required a bean of type 'org.hibernate.SessionFactory' that could not be found.</p>
  
  <p>Action:</p>
  
  <p>Consider defining a bean of type 'org.hibernate.SessionFactory' in your configuration.</p>
  
  <p>I have added implementation of my application:</p>
  
  <p><strong>POM.xml</strong></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.example&lt;/groupId&gt;
      &lt;artifactId&gt;demo&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;demo&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;1.5.2.RELEASE&lt;/version&gt;
          &lt;relativePath /&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
  
  
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Spring --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
              &lt;version&gt;4.2.2.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Hibernate dependency --&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
              &lt;version&gt;5.1.5.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
              &lt;version&gt;5.0.3.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  
  &lt;/project&gt;
  </code></pre>
  
  <p>application.property </p>
  
  <pre><code>spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  spring.datasource.url=jdbc:mysql://localhost:3306/test
  spring.datasource.username = root
  spring.datasource.password = root
  hibernate.dialect = org.hibernate.dialect.MySQLDialect
  spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
  </code></pre>
  
  <p><strong>Configuration class</strong></p>
  
  <pre><code>@Configuration
  @EnableTransactionManagement
  @ComponentScan({"configure"})
  @PropertySource({"classpath:application.properties"})
  public class HibernateConfiguration {
  
      @Autowired
      private Environment environment;
  
      @Bean
      public LocalSessionFactoryBean sessionFactory(){
          LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
          sessionFactory.setDataSource(dataSource());
          sessionFactory.setPackagesToScan(new String[]{"com.base","com.base.model"});
          sessionFactory.setMappingResources(new String[]{"Employee.hbm.xml"});
          sessionFactory.setHibernateProperties(hibernateProperties());
          return sessionFactory;
      }
  
      @Bean
      public Properties hibernateProperties() {
          Properties properties = new Properties();
          properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
          properties.put("hibernate.show_sql", environment.getRequiredProperty("hiberante.show_sql"));
          properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
          return properties;
      }
  
      @Bean
      public DataSource dataSource() {
              DriverManagerDataSource dataSource = new DriverManagerDataSource();
              dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.driverClassName"));
              dataSource.setUrl(environment.getRequiredProperty("jdbc.url"));
              dataSource.setUsername(environment.getRequiredProperty("jdbc.userName"));
              dataSource.setUsername(environment.getRequiredProperty("jdbc.password"));
          return dataSource;
      }
  
      @Bean  
      public SessionFactory sessionFactory(HibernateEntityManagerFactory hemf){  
          return hemf.getSessionFactory();  
      }  
  
  }
  </code></pre>
  
  <p><strong>Employee.java</strong></p>
  
  <pre><code>public class Employee implements Serializable{
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
  
      private int id;
  
      private String name;
  
      private String country;
  
      public int getId(){
          return this.id;
      }
  
      public void setId(int id){
          this.id = id;
      }
  
      public String getName(){
          return this.name;
      }
  
      public void setName(String name){
          this.name = name;
      }
  
      public void setCountry(String country){
          this.country = country;
      }
  
      public String getCountry(){
          return this.getCountry();
      }
  
      @Override
      public String toString() {
          return "Employee [id=" + id + ", name=" + name + ", country="
                  + country + "]";
      }
  }
  </code></pre>
  
  <p><strong>Employee.hbm.xml</strong></p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;  
  &lt;!DOCTYPE hibernate-mapping PUBLIC  
  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"  
  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"&gt;
  
  &lt;hibernate-mapping&gt;
      &lt;class name="com.base.model.Employee" table="Person"&gt;
          &lt;id name="id" type="java.lang.Integer"&gt;
              &lt;generator class="native"&gt;&lt;/generator&gt;
          &lt;/id&gt;
  
          &lt;property name="name" type="java.lang.String"&gt;
              &lt;column name="name" not-null="true"&gt;&lt;/column&gt;
          &lt;/property&gt;
          &lt;property name="country" type="java.lang.String"&gt;
              &lt;column name="country"&gt;&lt;/column&gt;
          &lt;/property&gt;
      &lt;/class&gt;
  
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p><strong>EmployeeDaoImpl</strong></p>
  
  <pre><code>@Component
  public class EmployeeDataDaoImpl  {
  
  
      @Autowired
      SessionFactory sessionFactory;
  
  
  public List&lt;Employee&gt; findAllEmployee(){
  ////    Criteria cri = getSession().createCriteria(Employee.class);
  //  List&lt;Employee&gt; dbList = cri.list();
  //  for (Employee employee : dbList) {
  //      System.out.println(employee.getCountry());
  //  }
      return null;
  }
  
  }
  </code></pre>
  
  <p>I have looked up the same error code on stackoverflow but none of the solutions worked and thus posting it here again with my code.
  Hoping someone else can point out where I am going wrong.</p>