Spring 引导尝试创建 class 从项目中删除
Spring boot tries to create class deleted from project
我已经从项目中删除了 Components
之一:
@Component
public interface ClientRepo extends CrudRepository<Client, Integer> {
}
并且我已将 Client
class 从 Entity
更改为 Embeddable
@Getter
@Setter
@Embeddable
public class Client {
@NotNull
@Size(max = 200)
private String email;
@NotNull
@Size(max = 200)
private String phoneNumber;
}
这里我用这个Client
class:
@Entity
@Table(name = "MEETINGS")
public class Meeting extends BaseEntity {
@Embedded
private Client client;
}
*这是我尝试启动项目时得到的结果:**
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: The given domain class does not contain an id attribute!
根据我的评论添加答案:
当您从项目中删除或重命名 class 时,请务必清理您的构建目录以摆脱其已编译的 .class 等价物。如果您使用的是 Maven,可以通过调用 clean 命令或手动删除 target 目录来完成。
不需要“ClientRepo”,因为“client”class 由 注释@Embeddable,它的所有列都将添加到数据库的“会议”class中。
这意味着,不会在您的数据库中由 JPA 生成和创建名为“client”的 table。
因此,您必须明确删除“ClientRepo”并改用“MeetingRepo”
我已经从项目中删除了 Components
之一:
@Component
public interface ClientRepo extends CrudRepository<Client, Integer> {
}
并且我已将 Client
class 从 Entity
更改为 Embeddable
@Getter
@Setter
@Embeddable
public class Client {
@NotNull
@Size(max = 200)
private String email;
@NotNull
@Size(max = 200)
private String phoneNumber;
}
这里我用这个Client
class:
@Entity
@Table(name = "MEETINGS")
public class Meeting extends BaseEntity {
@Embedded
private Client client;
}
*这是我尝试启动项目时得到的结果:**
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: The given domain class does not contain an id attribute!
根据我的评论添加答案: 当您从项目中删除或重命名 class 时,请务必清理您的构建目录以摆脱其已编译的 .class 等价物。如果您使用的是 Maven,可以通过调用 clean 命令或手动删除 target 目录来完成。
不需要“ClientRepo”,因为“client”class 由 注释@Embeddable,它的所有列都将添加到数据库的“会议”class中。
这意味着,不会在您的数据库中由 JPA 生成和创建名为“client”的 table。
因此,您必须明确删除“ClientRepo”并改用“MeetingRepo”