【发布时间】:2021-05-18 04:31:35
【问题描述】:
我使用了 2 个模块:
- 通用模块
- 用户模块
在 common 模块中,我使用了一个扩展 JPA Respository(例如:commonRepository)的接口来访问数据。 当我只运行公共模块时,它可以正常工作
我只是在POM.XML中的用户模块中添加了公共模块的依赖
在控制器中,我调用 common 模块的服务方法,其中 commonRepository 在 commonService 中自动装配
通用模块代码:
CommonController -> CommonServiceInterface -> CommonServiceImplementation (Autowired of CommonRepository) -> CommonRepository extends JPARespository -> getData()
用户模块代码:
UserController (Autowired of CommonServiceInterface )-> Access the getData() from CommonRespository
错误:
Field commonRepository in com.common.commonServiceImplementationrequired a bean of type 'com.common.repository.CommonRepository' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
注意: 如果我直接从 UserController 访问 CommonRepository 接口,它可以正常工作:
UserController (Autowired of CommonRepository)-> Access the getData() from CommonRespository
当我通过如下服务层访问时,会引发上述错误
UserController (Autowired of CommonServiceInterface )-> Access the getData() from CommonRespository
源代码在
【问题讨论】:
标签: spring-boot spring-mvc jpa spring-data-jpa