【SpringBoot整合JPA异常解决】Not a managed type: class cn.smbms.pojo.User

发布于:2024-04-28 ⋅ 阅读:(27) ⋅ 点赞:(0)

异常信息

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2024-04-23 15:34:11.731 ERROR 7920 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository' defined in cn.smbms.dao.UserRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class cn.smbms.pojo.User

异常原因

在实体类中加上注解@Entity即可

@Entity注解:

该注解是JPA(Java Persistence API)中的一个注解,用于标记一个类作为数据库中的实体对象。将该注解添加到一个类上,表示这个类可以被JPA用来映射到数据库表中,实体类的属性与数据库表的字段相对应。JPA是Java EE中的一种规范,用于实现对象关系映射(ORM),使得开发者可以使用面向对象的方式来操作数据库。


网站公告

今日签到

点亮在社区的每一天
去签到