我具有以下Maven项目结构:
eu.arrowhead
common
repository
-AJpaRepository.class
orchestrator
controller
-AController.class
OrchestratorApplication
other_modules...
其中两个模块是common
和orchestrator
。 Common是Orchestrator模块的依赖项。 JpaRepositoryClass
带有@Repository
注释。
在控制器类中,我使用构造函数自动装配来获取存储库的副本:
private final AJpaRepository serviceRepo;
@Autowired
public AController(AJpaRepository serviceRepo){
this.serviceRepo = serviceRepo;
}
最后,在Application类中,我使用scanBasePackages从通用模块中提取组件:
@SpringBootApplication(scanBasePackages = "eu.arrowhead")
public class OrchestratorApplication {
public static void main(String[] args) {
SpringApplication.run(OrchestratorApplication.class, args);
}
}
启动应用程序时,我得到:
Description:
Parameter 0 of constructor in eu.arrowhead.orchestrator.controller.ArrowheadServiceController required a bean of type 'eu.arrowhead.common.repository.ArrowheadServiceRepo' that could not be found.
Action:
Consider defining a bean of type 'eu.arrowhead.common.repository.ArrowheadServiceRepo' in your configuration.
如果我使用scanBasePackages = {"eu.arrowhead.common"}
,则应用程序启动时不会出现错误,但是我无法到达控制器类中的端点(获取默认404错误)。如果我写scanBasePackages = {"eu.arrowhead.common", "eu.arrowhead.orchestrator"}
就像只有“ eu.arrowhead”一样,在启动时会遇到相同的错误。
这应该如何工作?我对此表示高度怀疑。
后裔:
我也尝试使用@ComponentScan
,但结果相同。问题是什么?谢谢。