多个Spring数据源:考虑定义ExternalJarRepository类型的bean


@SpringBootApplication
@EnableJpaRepositories(basePackages=..,entityManagerRef=..)
@ComponentScan("com.main", "com.external.jar")
public class Application{
...
//methods defining primary datasource, transaction manager, entityManagerFactoryBean
}

外部罐子

@Configuration
@EnableJpaRepositories(basePackages="com.external.model", entityManagerRef=.., transactionManager=..)
public class ExternalDataConfig{
//methods defining datasource, transaction manager, entityManagerFactoryBean
}
public DataRepository extends CrudRepository<T,ID>{}
@Service 
public class ExternalService{
@Autowire
private DataRepository externalRepository;
}

错误Field externalRepository in com.external.jar.ExternalService required a bean of type DataRepository'

然而,日志表明成功扫描了默认和外部存储库,不确定为什么依赖注入机制无法找到bean

.s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
.s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
.s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 55ms. Found 3 JPA repository interfaces.
.s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
.s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
.s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 75ms. Found 21 JPA repository interfaces.

发现默认应用程序也有一个名为DataRepository的bean,并且应用程序设置允许bean覆盖

spring:
main:
allow-bean-definition-overriding: true

在外部依赖中重命名DataRepositorybean完成了的任务

相关内容

  • 没有找到相关文章

最新更新