考虑在配置中定义类型为"org.hibernate.SessionFactory"的bean [英] Consider defining a bean of type 'org.hibernate.SessionFactory' in your configuration
本文介绍了考虑在配置中定义类型为"org.hibernate.SessionFactory"的bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是JavaEE的新手,我一直在从事simlpe Springboot项目.每次我运行它,我都会收到此错误:
I am new to JavaEE and i have been working on a simlpe Springboot project. Each time i run it i get this error:
请随时回答我的问题,代码中的任何改进都是高度赞赏的.
Please feel free to answer to my question and any improvemnet in the code is Highly Appreciate.
Field sessionFactory in com.example.dao.CartDaoImpl required a bean of type 'org.hibernate.SessionFactory' that could not be found.
Action:
Consider defining a bean of type 'org.hibernate.SessionFactory' in your configuration.
推荐答案
可以从已经在 spring-boot-starter-data-jpa
中配置的EntityManager中获取会话.因此,注入EntityManager而不是SessionFactory:
It is possible to get Session from EntityManager which is already configured in spring-boot-starter-data-jpa
. So inject EntityManager instead of SessionFactory:
@Autowired
private EntityManager entityManager;
private Session getSession() {
return entityManager.unwrap(Session.class);
}
并在需要的地方使用getSession()方法.
And use getSession() method where you need.
这篇关于考虑在配置中定义类型为"org.hibernate.SessionFactory"的bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文