SpringBoot中的应用程序运行失败

时间:2020-10-31 16:44:44

标签: java spring spring-boot

我正在通过一个教程学习SpringBoot,它使用公司员工数据库的API构建示例网站。当我尝试运行该应用程序时,收到以下消息:

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadDatabase' defined in file [/Users/westonjorgensen/Downloads/payroll/target/classes/com/company/payroll/LoadDatabase.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.company.payroll.LoadDatabase$$EnhancerBySpringCGLIB$$6abc07cf]: Constructor threw exception; nested exception is java.lang.Error: Unresolved compilation problems: 
The declared package "payroll" does not match the expected package "com.company.payroll"
The method save(Employee) is undefined for the type EmployeeRepository
The method save(Employee) is undefined for the type EmployeeRepository

整个项目在这里https://github.com/wjorgensen/payroll.git

我正在关注的教程是https://spring.io/guides/tutorials/rest/

关于如何解决此问题的任何想法?

1 个答案:

答案 0 :(得分:2)

有包装问题。

该异常提到<...>/com/company/payroll/LoadDatabase.class,但是您的项目在LoadDatabase.java中不包含src/main/java/com/company/payroll类。尝试按照您所遵循的教程中的说明,将所有类从com.company.payroll包迁移到payroll包。