java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required in spring+hibernate

前端 未结 4 387
暗喜
暗喜 2021-01-18 00:11

I am doing spring + hibernate apllication. When I run the application on tomcat server I am getting some exception. Below is my code.

This is my bean config file.

4条回答
  •  逝去的感伤
    2021-01-18 01:09

    I had the same problem and fix it by using Autowired constructor with EntityManagerFactory. Keyur answer is correct

    @Service
    class EmployeeDaoImpl @Autowired constructor(
            factory: EntityManagerFactory
    ) : HibernateDaoSupport(), EmployeeDao {
    
        init {
            if (factory.unwrap(SessionFactory::class.java) == null) {
                throw NullPointerException("factory is not a hibernate factory")
            }
            setSessionFactory(factory.unwrap(SessionFactory::class.java))
        }
        ...
    
    }
    

提交回复
热议问题