Я строю простые отношения ManyToOne, используя Spring JAP. я получаю UnsatisfiedDependencyException Ошибка с именем бина Неудовлетворенная зависимость, выраженная через поле
UnsatisfiedDependencyException: Ошибка создания бина с именем 'procjectController': Unsatisfied
Вот мой файл. 1007
project.java
package com.ganesh.dto;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
public class Project {
@Id
private int projectId;
private String projectName;
//Relation establish
@ManyToOne(
fetch = FetchType.LAZY,
optional = false
)
@JoinColumn(
name = "employee_id",
nullable = false
)
@JsonIgnore
private Employee employee;
public Project() {
}
public Project(int projectId, String projectName, int eId) {
super();
this.projectId = projectId;
this.projectName = projectName;
//Adding employee
this.employee = new Employee(eId,"","");
}
public int getProjectId() {
return projectId;
}
public void setProjectId(int projectId) {
this.projectId = projectId;
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
//Adding getter and setters Employee reference
public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
}
ProjectDao.java
package com.ganesh.dao;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.ganesh.dto.Project;
@Repository
public interface ProjectDao extends JpaRepository<Project, Integer> {
List<Project> findEmployeeById(int eId);
}
ImpProjectService.java
package com.ganesh.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ganesh.dao.*;
import com.ganesh.dto.Project;
@Service
public class ImpProjectService implements ProjectService {
@Autowired
private ProjectDao projectDao;
@Override
public List<Project> getProjectList(int eId) {
System.out.println("in Dao class employee id"+ eId);
return projectDao.findEmployeeById(eId);
}
@Override
public Project getProjectById(int id) {
return projectDao.getOne(id);
}
@Override
public void addProject(Project project) {
projectDao.save(project);
}
@Override
public void updateProject(Project project) {
projectDao.save(project);
}
@Override
public void deleteProjectById(int id) {
projectDao.deleteById(id);
}
@Override
public List<Project> getAllProject() {
return projectDao.findAll();
}
}
ProcjectController.java
package com.ganesh.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.ganesh.dto.*;
import com.ganesh.service.*;
@RestController
public class ProcjectController {
@Autowired
private ImpProjectService projectService;
@RequestMapping("/projects")
public List<Project> getProjectList(){
return projectService.getAllProject();
}
@RequestMapping("/employees/{eId}/projects")
public List<Project> getAllProjects(@PathVariable int eId){
System.out.println("In Project Controller");
List<Project> projList = projectService.getProjectList(eId);
System.out.println(projList);
return projList;
}
@RequestMapping("/employees/{eId}/projects/{id}")
public Project getProjectById(@PathVariable int id) {
return projectService.getProjectById(id);
}
@RequestMapping(method = RequestMethod.POST, value="/employees/{eId}/projects")
public void addProject(@RequestBody Project project, @PathVariable int eId) {
project.setEmployee(new Employee(eId,"",""));
projectService.addProject(project);
}
@RequestMapping(method = RequestMethod.PUT, value="/employees/{eId}/projects/{id}")
public void updateProject(@RequestBody Project project, @PathVariable int eId) {
project.setEmployee(new Employee(eId,"",""));
projectService.updateProject(project);
}
@RequestMapping(method = RequestMethod.DELETE, value="/projects/{id}")
public void deleteProjecstById(@PathVariable int id) {
projectService.deleteProjectById(id);
}
}