当前位置: 首页 > 知识库问答 >
问题:

组织。springframework。豆。工厂BeanCreationException:创建名为“projectTaskRepository”的bean时出错

郭洋
2023-03-14

我正在做项目的Spring启动...但是得到了这个错误,而运行应用程序。这可能是H2数据库错误。但是要解决这个错误localhost应该运行,但程序在部署前终止...所以我不能看到什么是实际问题。

错误:org.springframework.beans.factory.BeanCreationException:创建名称为'project TaskRepository'的bean时出错com.agileintelligence.projectdashboard.repository.在JpaRepositories注册器上声明的@EnableJpaRepositories中定义的ProjectTaskRepository。EnableJpaRepositoriesConfiguration:在设置bean属性'mappingContext'时无法解析对bean'jpaMappingContext'的引用;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为'jpaMappingContext'的bean时出错:调用init方法失败;嵌套异常是org.hibernate.注释异常:未为实体指定标识符:com.agileintelligence.projectdashboard.domain.project任务

表类

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

服务等级

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> {

}

共有1个答案

梁丘扬
2023-03-14

您使用的Id导入错误。

import org.springframework.data.annotation.Id;

将上面的替换为下面的持久性包。

import javax.persistence.Id

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

 类似资料: