No identifier specified for entity没有为实体指定标识符

异常

No identifier specified for entity没有为实体指定标识符_第1张图片

ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userController’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userServiceImpl’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userDao’ defined in com.william.dao.UserDao defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean ‘jpaMappingContext’ while setting bean property ‘mappingContext’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘jpaMappingContext’: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.william.domain.User
No identifier specified for entity没有为实体指定标识符_第2张图片
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userController’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userServiceImpl’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userDao’ defined in com.william.dao.UserDao defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean ‘jpaMappingContext’ while setting bean property ‘mappingContext’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘jpaMappingContext’: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.william.domain.User

异常原因翻译:

ConfigServletWebServerApplicationContext:在上下文初始化期间遇到的异常——取消刷新尝试:org.springframework.bean .factory。BeanCreationException:创建名为“userController”的bean时出错:注入资源依赖失败;嵌套异常是org.springframe .bean .factory。BeanCreationException:创建名为“userServiceImpl”的bean时出错:注入资源依赖失败;嵌套异常是org.springframe .bean .factory。BeanCreationException:创建名为“userDao”的bean时出错,该bean在com. williams .dao中定义。UserDao定义在jpareposoriesregistrar上声明的@ enablejparepospos存中。EnableJpaRepositoriesConfiguration:在设置bean属性“mappingContext”时无法解析对bean“jpaMappingContext”的引用;嵌套异常是org.springframe .bean .factory。创建名为“jpaMappingContext”的bean时出错:init方法调用失败;嵌套异常是org.hibernate。注释异常:没有为实体指定标识符:com. williams .domain. user

问题根本原因:

注释异常:没有为实体指定标识符:com. williams .domain. user

实体类加入@Id

No identifier specified for entity没有为实体指定标识符_第3张图片

package com.william.domain;



import javax.persistence.*;

/**
 * @author :lijunxuan
 * @date :Created in 2020/5/30  12:29
 * @description :
 * @version: 1.0
 */
@Table(name = "user")
@Entity
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private String username;
    private String password;
    private String name;

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", name='" + name + '\'' +
                '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

你可能感兴趣的:(微服务)