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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值