Spring boot SpringBoot scanBasePackages在多模块项目中不工作
我有以下maven项目结构:Spring boot SpringBoot scanBasePackages在多模块项目中不工作,spring-boot,Spring Boot,我有以下maven项目结构: eu.arrowhead common repository -AJpaRepository.class orchestrator controller -AController.class OrchestratorApplication other_modules... 其中两个模块是通用和编排器。Common是Orchestrator模块的依赖项。JpaRepositoryClass用@Repos
eu.arrowhead
common
repository
-AJpaRepository.class
orchestrator
controller
-AController.class
OrchestratorApplication
other_modules...
其中两个模块是通用
和编排器
。Common是Orchestrator模块的依赖项。JpaRepositoryClass
用@Repository
注释
在控制器类中,我使用构造函数自动连接来获取存储库的副本:
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”一样,我在启动时会收到相同的错误
这是怎么回事?我对此深表怀疑
家属:
- 公共模块:starter数据jpa、starter json、mysql连接器java、hibernate验证器
- Orch模块:starter web,通用模块
我还尝试使用
@ComponentScan
,但结果相同。有什么问题?谢谢。您缺少启用Spring数据JPA存储库扫描的注释。注释太多了!我已经将其放在应用程序类上,现在我从repository init方法中获得“IllegalArgumentException:非托管类型:class eu.arrowhead.common.dto.entity.ArrowheadService”。此类上只有@Entity注释。我想使用这个额外的注释可能会减少一些自动配置?添加第三个@EntityScan注释也解决了这个问题。当我只有一个模块时,这些模块是不需要的:(哦,好吧。我有点担心以后我会发现更多缺少的东西,因为自动配置现在没有应用。