我有以下Maven项目结构:
eu.arrowhead
common
repository
-AJpaRepository.class
orchestrator
controller
-AController.class
OrchestratorApplication
other_modules...
其中两个模块
common
和
orchestrator
. Common是Orchestrator模块的依赖项。这个
JpaRepositoryClass
用注释
@Repository
.
在Controller类中,我使用构造函数autowiring获取存储库的副本:
private final AJpaRepository serviceRepo;
@Autowired
public AController(AJpaRepository serviceRepo){
this.serviceRepo = serviceRepo;
}
最后,在应用程序类中,我使用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”一样,启动时也会出现同样的错误。
这是怎么工作的吗?我非常怀疑。
家属:
-
通用模块:启动器数据JPA、启动器JSON、MySQL连接器Java、Hibernate验证器
-
ORCH模块:Starter Web,通用模块。
我也试过用
@ComponentScan
但结果是一样的。有什么问题?谢谢。