问题描述:程序启动不成功,报错: Not a managed type: class com.xxx.common.user.Product
代码的实体类如下所示:
@Entity
@Data
@Table(name="shop_product")
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer pid;//主键
private String pname;//商品名称
private Double pprice;//商品价格
private Integer stock;//库存
}
对应的注解也有,但是启动却报错 Not a managed type: class com.xxx.common.user.Product
报错说的应该是该实体类并不在管理内,猜测可能注解没识别到。
解决方案:在启动类上加上扫描解决
@SpringBootApplication
@EntityScan("com.xxx.common.user")//不加该注解以及对应路径 找不到对应实体类
public class ProductApplication {
public static void main(String[] args) {
SpringApplication.run(ProductApplication.class, args);
}
}