我正在开发一个Spring引导应用程序。在尝试了许多解决方案后,它没有得到解决。请帮助:
控制台:org。springframework。豆。工厂UnsatisfiedPendencyException:创建名为“doctorController”的bean时出错:通过字段“doctorService”表示未满足的依赖关系;嵌套的异常是org。springframework。豆。工厂UnsatisfiedDependencyException:创建名为“doctorService”的bean时出错:通过字段“doctorRepo”表示的未满足的依赖关系;嵌套的异常是org。springframework。豆。工厂BeanCreationException:创建名为“doctorRepository”的bean时出错:调用init方法失败;嵌套的异常是org。springframework。数据映射。PropertyReferenceException:找不到类型医生的属性id!
原因:org。springframework。豆。工厂UnsatisfiedDependencyException:创建名为“doctorService”的bean时出错:通过字段“doctorRepo”表示的未满足的依赖关系;嵌套的异常是org。springframework。豆。工厂BeanCreationException:创建名为“doctorRepository”的bean时出错:调用init方法失败;嵌套的异常是org。springframework。数据映射。PropertyReferenceException:找不到类型医生的属性id!
控制器:
@RestController
public class DoctorController {
@Autowired
private DoctorService doctorService;
@RequestMapping("/hms/doctor")
public List<Doctor> getAllDoctor()
{
return doctorService.getAllDoctor();
}
@RequestMapping(method=RequestMethod.POST,value="hms/doctor")
public void addDoctor(@RequestBody Doctor doctor)
{
doctorService.addDoctor(doctor);
}
}
服务类别:
@Service
public class DoctorService {
Logger logger= LoggerFactory.getLogger(DoctorService.class);
@Autowired
private DoctorRepository doctorRepo;
public List<Doctor> getAllDoctor(){
logger.error("error happened");
logger.trace(" Error !!!");
List<Doctor> doctor= new ArrayList<Doctor>();
doctorRepo.findAll().forEach(doctor::add);
return doctor;
}
public Doctor getDoctorById(String doctorId) {
return doctorRepo.findById(doctorId);
}
public Doctor getDoctorByPhoneNumber(long phoneNumber)
{
return doctorRepo.findByPhoneNumber(phoneNumber);
}
public void addDoctor(Doctor doctor) {
doctorRepo.save(doctor);
}
public void updateDoctor(String doctorId,Doctor doctor) {
doctorRepo.save(doctor);
}
}
存储库:
public interface DoctorRepository extends CassandraRepository<Doctor, Integer>
{
Doctor findById(String doctorId);
Doctor findByPhoneNumber(long phoneNumber);
void deleteById(String doctorId);
}
模型类:
@Entity
public class Doctor {
@GeneratedValue(strategy=GenerationType.SEQUENCE)
@PrimaryKey
private int doctorId;
private String doctorName;
private long phoneNumber;
private String specialization;
private int totalExperience;
private String workingDays[]= {"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
public Doctor() {
}
public Doctor(int doctorId, String doctorName, long phoneNumber, String specialization, int totalExperience,
String[] workingDays) {`enter code here`
super();
this.doctorId = doctorId;
this.doctorName = doctorName;
this.phoneNumber = phoneNumber;
this.specialization = specialization;
this.totalExperience = totalExperience;
this.workingDays = workingDays;
// getters and setters
波姆。xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.fullstack.assessment</groupId>
<artifactId>hms</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>hms</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
医生的身份证是医生身份证,所以
Doctor findById(...
void deleteById(...
应该是
Doctor findByDoctorId(...
void deleteByDoctorId(...
或者使用getter和setter将doctorId
更改为简单的id
。
问题是,每次我运行该项目时,都会从org中发现错误。springframework。豆。工厂“未满足的支出”异常弹出窗口。 我已经尝试了几个相关的问题和答案,但是问题还没有解决。 FieldDataService。JAVA FieldDataServiceImpl。JAVA FieldDataDao。JAVA FieldDataDaoImpl.java 现场数据。JAVA 现场数据。xml ...
我正在尝试用mysql和flyway运行我的Spring项目引导 我的环境: > Linux 18.04 Java 1.8.0_201 application.yml v1__init.sql user.java
代码应该使用ApacheCamel路由将文件夹1中的内容复制到文件夹2,该路由使用Quartz触发。当我运行程序时,我会得到以下错误:“org。springframework。豆。工厂未满足的依赖项异常:创建名为“springCamelApplication”的bean时出错:未满足的依赖项通过字段“camelContext”和“由:org引起”表示。springframework。豆。工厂Bea
为什么自动加载依赖项的注入失败。 严重:上下文初始化失败。springframework。豆。工厂BeanCreationException:创建名为“homeController”的bean时出错:自动连线依赖项的注入失败;嵌套的异常是org。springframework。豆。工厂BeanCreationException:无法自动关联字段:com。快速启动。通用域名格式。springmvc。
尝试使用异常消息导航到“客户”时出现异常
当没有堆栈跟踪时,我如何知道问题是什么?我可以启用某些选项吗?我刚刚用spring初始化器创建了一个小项目,这就是我得到的 更新的日志(带有调试标志)