为了账号安全,请及时绑定邮箱和手机立即绑定

在 Spring Boot 应用程序中获取类未找到异常错误

在 Spring Boot 应用程序中获取类未找到异常错误

慕容森 2021-12-30 20:37:44
权威.javapackage com.easkart.domain.security;import org.springframework.security.core.GrantedAuthority;public class Authority implements GrantedAuthority {/** *  */private static final long serialVersionUID = 5888173406859788817L;private final String authority;public Authority(String authority) {    this.authority = authority;}@Overridepublic String getAuthority() {    return authority;}}角色.javapackage com.easkart.domain.security;import java.util.HashSet;import java.util.Set;import javax.persistence.CascadeType;import javax.persistence.Entity;import javax.persistence.FetchType;import javax.persistence.Id;import javax.persistence.OneToMany;@Entitypublic class Role {@Idprivate int roleId;private String name;@OneToMany(mappedBy = "role", cascade = CascadeType.ALL, fetch = FetchType.LAZY)private Set<UserRole> userRoles = new HashSet<>();public int getRoleId() {    return roleId;}public void setRoleId(int roleId) {    this.roleId = roleId;}public String getName() {    return name;}public void setName(String name) {    this.name = name;}public Set<UserRole> getUserRoles() {    return userRoles;}public void setUserRoles(Set<UserRole> userRoles) {    this.userRoles = userRoles;}}当我将此代码作为 Spring 启动应用程序运行时;我得到以下异常2018-11-05 22:21:35.643 错误 5136 --- [main] osboot.SpringApplication:应用程序运行失败 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org 中定义名称为“entityManagerFactory”的 bean 创建时出错/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]:调用init方法失败;嵌套异常是 org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [com.easkart.domain.User] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1745 ) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory。请帮帮我。
查看完整描述

2 回答

?
慕田峪4524236

TA贡献1875条经验 获得超5个赞

将您的 Main, 移动到根包。所以你的结构看起来像下面这样。

src/main/java
    -> EaskantApplication (which I guess is the Main class)
        -> All other packages

通常,当 Main 类不在根目录下时,它往往无法找到所需的资源。


查看完整回答
反对 回复 2021-12-30
?
翻阅古今

TA贡献1780条经验 获得超5个赞

将 EaskartApplication.java 移动到一个新包,例如 com.easkart.app


查看完整回答
反对 回复 2021-12-30
  • 2 回答
  • 0 关注
  • 119 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号