我正在使用Spring boot Security,当我想运行它时,我发现了一个错误
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: Use of @OneToMany or @ManyToMany targeting an unmapped class: xxxxxxxxxx [java.security.Permission]
我不知道如何解决这个问题,我是Spring的新手。 感谢您的阅读和时间。
@Entity
@Table(name = "ROLES")
public class Role implements Serializable, GrantedAuthority {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(unique = true)
private String name;
@ManyToMany
@JoinTable(
name = "role_permissions",
joinColumns= {@JoinColumn(name="role_id", referencedColumnName="id")},
inverseJoinColumns= {@JoinColumn(name="permission_id", referencedColumnName="id")}
)
@LazyCollection(LazyCollectionOption.FALSE)
private Set <Permission> permission;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set<Permission> getPermission() {
return permission;
}
public void setPermission(Set<Permission> permission) {
this.permission = permission;
}
public Role() {}
public Role(String name) {
this.name = name;
}
@Override
public String getAuthority() {
// TODO Auto-generated method stub
return getName();
}
@Override
public String toString() {
return "Role [id=" + id + ", name=" + name + ", permission=" + permission + "]";
}
}
权限等级
@Entity
@Table(name="PERMISSIONS")
public class Permissions implements GrantedAuthority {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(unique = true)
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Permissions() {}
public Permissions( String name) {
this.name = name;
}
@Override
public String getAuthority() {
// TODO Auto-generated method stub
return name;
}
@Override
public String toString() {
return "permissions [id=" + id + ", name=" + name + "]";
}
}
答案 0 :(得分:0)
您输入的错误Set<Permission>
是java.security.Permission
。因此,将其更改为您自己的类文件Set<Permissions>
。