下面是我的档案:
Recruiter.java
package com.jobapplication.recruiterservice.model;
import javax.persistence.*;
import java.util.UUID;
@Entity
public class Recruiter {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private int id;
@Column(name = "name")
private String name;
@Column(name="email")
private String email;
@Column(name="uuid")
private String uuid;
public Recruiter(int id, String name, String email, String uuid) {
this.id = id;
this.name = name;
this.email = email;
this.uuid = UUID.randomUUID().toString();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}
招聘控制员:
package com.jobapplication.recruiterservice.controller;
import com.jobapplication.recruiterservice.model.Recruiter;
import com.jobapplication.recruiterservice.service.RecruiterService;
import org.springframework.beans.factory.annotation.Autowired;
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;
@RestController
public class RecruiterController {
@Autowired
RecruiterService recruiterService;
//The below function adds a recruiter to the company
@RequestMapping(method = RequestMethod.POST, value="recruiter/addRecruiter")
public void addRecruiter(@RequestBody Recruiter recruiter){
recruiterService.addRecruiter(recruiter);
}
}
RecruiterRepo:
package com.jobapplication.recruiterservice.repository;
import com.jobapplication.recruiterservice.model.Recruiter;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface RecruiterRepo extends JpaRepository<Recruiter, String> {
}
招聘服务:
package com.jobapplication.recruiterservice.service;
import com.jobapplication.recruiterservice.model.Recruiter;
import com.jobapplication.recruiterservice.repository.RecruiterRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class RecruiterService {
@Autowired
RecruiterRepo recruiterRepo;
public void addRecruiter(Recruiter recruiter) {
recruiterRepo.save(recruiter);
}
}
招聘服务申请:
package com.jobapplication.recruiterservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class RecruiterServiceApplication {
public static void main(String[] args) {
SpringApplication.run(RecruiterServiceApplication.class, args);
}
}
我试图运行springboor应用程序。SpringBoot应用程序应该已经启动。
我得到:
未满足的依赖项异常:创建名为“recruiterController”的bean时出错:通过字段“recruiterService”表示的未满足依赖关系:创建名为“recruiterService”的bean时出错:通过字段“recruiterRepo”表示的未满足依赖关系:创建在com.jobapplication.recruiterservice.repository中定义的名为“recruiterRepo”的bean时出错。在JpaRepositoriesRegistrar上声明的@EnableJpaRepositories中定义的RecruiterRepo。EnableJpaRepositoriesConfiguration:不是托管类型:类别com.jobapplication.recruiterservice.model.Recruiter
1条答案
按热度按时间w1jd8yoj1#
EnableJpaRepositoriesConfiguration的错误是:非托管类型:类别com.jobapplication.recruiterservice.model.Recruiter
这个错误的原因是JPA在每个Entity类中需要一个非参数构造函数。否则JPARepository无法管理它。
解决方案
添加不带参数的构造函数。使用Lombok可以轻松完成: