No identifier specified for entity沒有爲實體指定標識符

異常

在這裏插入圖片描述

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
在這裏插入圖片描述
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

在這裏插入圖片描述

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;
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章