java - 在文件中定义名称为“covidController”的 Spring 错误创建 bean
问题描述
首先,您可能认为/投票这个问题是重复的。让我告诉你,我已经尝试了几乎所有可能的解决方案,而不是 SO。
我正在为一个项目使用 Spring 框架,该项目基于分层架构。我试图修复启动 Spring 时引发的异常。最近几天我试图解决这个问题,但我无法解决它。(我是春天的新手)
我有三层:
- 领域
- 坚持
- 休息
当我启动应用程序时,它会抛出一个错误:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'covidController' defined in file [......./layered-architecture-spring/rest/target/classes/com/comp/rest/CovidController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'covidRepository' defined in com.comp.persistence.CovidRepository defined in @EnableJpaRepositories declared on RestApp: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.comp.persistence.CovidRepository.fetchAllData()! No property fetchAllData found for type Covid!
Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.comp.persistence.CovidRepository.fetchAllData()! No property fetchAllData found for type Covid!
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property fetchAllData found for type Covid!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:94) ~[spring-data-commons-2.3.0.RELEASE.jar:2.3.0.RELEASE]
我在 GitHub 上的整个项目:https ://github.com/Phoenix404/ssa-layered-assignment
@RestController
public class CovidController {
private final CovidRepository covidRepository;
public CovidController(CovidRepository cr) {
covidRepository = cr;
}
@GetMapping("/cdata")
public List<Covid> getList() {
return this.covidRepository.findByLocation("italy");
}
}
@Repository
public interface CovidRepository extends JpaRepository<Covid, Integer> {
List<Covid> fetchAllData();
List<Covid> findByDate(Date date);
List<Covid> findByLocation(String location);
}
CovidController
是我在休息模块内的休息应用程序控制器。在CovidRepository
持久性模块中。
我正在使用以下注释来扫描其他 SO 上建议的类,但我仍然收到错误:
@SpringBootApplication
@EnableJpaRepositories("com.comp.**persistence**")
@EntityScan(basePackages = {"com.comp.**"})
@ComponentScan(basePackages = {"com.comp.**"})
@SpringBootApplication
@EnableJpaRepositories("com.comp.persistenc*")
@EntityScan(basePackages = {"com.comp"})
@ComponentScan(basePackages = {"com.comp"})
@SpringBootApplication
@EnableJpaRepositories("com.comp.*")
@EntityScan(basePackages = {"com.comp.*"})
@ComponentScan(basePackages = {"com.comp.*"})
我究竟做错了什么?
解决方案
感谢@aniket-sahrawat 解决了这个问题。
当我从covidRepository
.
推荐阅读
- c# - 当我使用 invokemember () Webbrowser 按下按钮时出现错误
- ios - UINavigationView 弹出到根视图控制器问题
- php - 从 cmd 运行时,来自 WAMP 服务器的 PHP 没有看到 .htaccess 文件
- google-apps-script - 类表方法 getActiveCell、getCurrentCell、getActiveRange 无法按预期工作
- ejabberd - 如何使用 Smack Client 在 Ejabberd 中注册带内用户,特别是虚拟主机?
- javascript - 将两个代码合二为一 - 检查 url 是否存在/登录
- ios - 在谷歌地图中使用谷歌可拖动标记时用户界面没有响应
- mysql - 在多个一对多表上的 Mysql 上获取 group by 数据的问题
- laravel - Laravel 5.8 - 从采摘结果中获取值
- json - 在 SQL Server 中为我的选择查询读取 JSON 数据