[英]Spring - import jpa repositories from another module
I have two gradle modules: common
and app
我有两个 gradle 模块:
common
和app
The common
module contains a JpaRepository named OutboxJpaMessageRepository
. common
模块包含一个名为 OutboxJpaMessageRepository 的OutboxJpaMessageRepository
。
The app
module contains another JpaRepository named RentRepository
. app
模块包含另一个名为 RentRepository 的RentRepository
。
The common
has the following configuration class, which is auto-imported by the other module (using a spring.factories
file): common
具有以下配置 class,它由其他模块自动导入(使用spring.factories
文件):
@Configuration
@EntityScan("path.to.common.module")
@EnableJpaRepositories("path.to.common.module")
@ComponentScan("path.to.common.module")
public class OutboxMessagingAutoConfig {
}
The problem is that @EnableJpaRepositories("path.to.common.module")
overrides the default auto-configuration of the application, and the app can't find RentRepository
(different package).问题是
@EnableJpaRepositories("path.to.common.module")
覆盖了应用程序的默认自动配置,并且应用程序找不到RentRepository
(不同的包)。
Can a library exports jpa repositories without override the default configuration of the client?库可以导出 jpa 个存储库而不覆盖客户端的默认配置吗?
I don't want to re-configure all apps which use the common module我不想重新配置所有使用公共模块的应用程序
Two solutions I can think of:我能想到的两种解决方案:
The boot
module must contain multi path lick this: boot
模块必须包含多路径舔这个:
@ComponentScan({"path.to.common.module", "path.to.app.module"})
@ComponentScan({"path.to.common.module", "path.to.app.module"})
I found the solution to my problem.我找到了解决问题的办法。
I solved using @AutoConfigurationPackage
我解决了使用
@AutoConfigurationPackage
@Configuration
@AutoConfigurationPackage
@ComponentScan("path.to.common.module")
public class OutboxJpaMessagingConfig {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.