Error creating bean with name 'entityManagerFactory' defined in class path resource 解决方法

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.example.vo.ProductSearch
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1762) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$110/795279127.getObject(Unknown Source) ~[na:na]
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
	at com.example.jingdong.JingdongApplication.main(JingdongApplication.java:10) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_20]
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.1.3.RELEASE.jar:2.1.3.RELEASE]
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.example.vo.ProductSearch
	at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:266) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]

	... 22 common frames omitted

总结:当看到entityManagerFactory的时候想到要想到@Entity这个注释。[@Entity] 必须与@Id注解 结合使用 代表数据库中的实体类。
我的这个类是并不是表的实体类,也没有将表中的属性进行注释标注,而在类名上面使用了@Entity这个注释所以报错。去掉即可(要细心,别脑子一热就用);
还有一种情况那就是表的实体类忘记使用@Entity,加上即可。

猜你喜欢

转载自blog.csdn.net/zhang_cl_cn/article/details/88649032