springboot整合JPA出现异常java.lang.IllegalArgumentException: Not a managed type: class xxx

it2025-02-13  7

springboot整合JPA出现异常java.lang.IllegalArgumentException: Not a managed type: class xxx

当出现以下这个异常时 可通过下面几个方法来解决:

①dao类必须继承JpaRepository类且JpaRepository必须加泛型,其中泛型写法为<bean类,主键数据类型> ②在启动类加上扫描实体类的注解 @EntityScan (basePackages = “com.zl.bean”) ③实体类记得加上@Entity注解和@Table注解,且主键得加上@id注解和@GeneratedValue注解

最新回复(0)