org.springframework.beans.factory.BeanCreationException:创建名称为 'projectTaskRepository' 的 bean 时出错

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'projectTaskRepository'

我正在 spring 启动时做项目...但是在 运行 启动应用程序时出现此错误。可能是H2数据库错误。但是要解决错误,localhost 应该 运行 但是程序在部署之前就终止了。所以我看不出真正的问题是什么。

错误:org.springframework.beans.factory.BeanCreationException:在 JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration 上声明的 @EnableJpaRepositories 中定义 com.agileintelligence.projectdashboard.repository.ProjectTaskRepository 中定义名称 'projectTaskRepository' 创建 bean 时出错:无法解析对 bean 的引用 'jpaMappingContext' 同时设置 bean 属性 'mappingContext';嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为 'jpaMappingContext' 的 bean 时出错:调用 init 方法失败;嵌套异常是 org.hibernate.AnnotationException:没有为实体指定标识符:com.agileintelligence.projectdashboard.domain.projectTask

Table class

package com.agileintelligence.projectdashboard.domain;
import org.springframework.data.annotation.Id;
import javax.persistence.Entity; 
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.validation.constraints.NotBlank;

@Entity
public class projectTask {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;

@NotBlank(message = "Summary cannot be empty")
private String summary;
private String acceptanceCriteria;
private String status;

public projectTask() {
}

public long getId() {
    return id;
}

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

public String getSummary() {
    return summary;
}

public void setSummary(String summary) {
    this.summary = summary;
}

public String getAcceptanceCriteria() {
    return acceptanceCriteria;
}

public void setAcceptanceCriteria(String acceptanceCriteria) {
    this.acceptanceCriteria = acceptanceCriteria;
}

public String getStatus() {
    return status;
}

public void setStatus(String status) {
    this.status = status;
}
}

控制器

package com.agileintelligence.projectdashboard.web;

import com.agileintelligence.projectdashboard.domain.projectTask;
import com.agileintelligence.projectdashboard.service.ProjectTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/board")
@CrossOrigin
public class ProjectTaskController {

    @Autowired
    private ProjectTaskService service;

    @PostMapping("")
    public ResponseEntity<?> addProjectTaskToBoard(@RequestBody projectTask projectTask){

        com.agileintelligence.projectdashboard.domain.projectTask newPT = service.saveOrUpdateProjectTask(projectTask);
        return new ResponseEntity<>(newPT, HttpStatus.CREATED);
    }
}

服务Class

package com.agileintelligence.projectdashboard.service;

import com.agileintelligence.projectdashboard.domain.projectTask;
import com.agileintelligence.projectdashboard.repository.ProjectTaskRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProjectTaskService {

    @Autowired
    private ProjectTaskRepository projectTaskRepository;

    public projectTask saveOrUpdateProjectTask(projectTask projectTask){

        //In case if status is not set,automatically push it to TO_DO
        if(projectTask.getStatus()==null||projectTask.getStatus().equals("")){
            projectTask.setStatus("TO_DO");
        }
        return projectTaskRepository.save(projectTask);
    }
}

存储库

package com.agileintelligence.projectdashboard.repository;

import com.agileintelligence.projectdashboard.domain.projectTask;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ProjectTaskRepository extends CrudRepository<projectTask,Long> {

}

您在此处使用了错误的 Id 导入。

import org.springframework.data.annotation.Id;

用持久性包中的以下内容替换上面的内容。

import javax.persistence.Id

奖励:使用 ProjectTask(P 大写)重命名您的实体,以防止将来出现奇怪的问题。