0

我们使用spring++spring data jpa repositories作为maven构建环境。我们在多个云环境中部署我们的项目战。

对于特定的云环境,我们从数据库中检索登录凭据。例如。因为AWS我们可能有AWSCredentials域对象并且我们可能有域对象和AWSCredentialsRepositoryAzureAzureCredentialsAzureCredentialsRepository

spring data jpa 中是否有一种方法可以使用构建脚本中的某些参数有条件地加载存储库?

例如:我想部署到 Azure 云。所以我只需要AzureCredentialsdomainAzureCredentialsRepository而不是AWS.

有没有一种优雅的方式来做到这一点spring

4

1 回答 1

0

可悲的是,我认为这将适用于 java-config。(我必须用这个巫术替换 applicationContext.xml 才能让“可选的 jpa 存储库”工作。

我找不到 applicationContext.xml .. xml IoC 来解决这个问题。

就我而言,我希望本地开发人员(spring-profile=default)使用 H2 数据库来存储一些信息,但是“真实代码”......非默认 spring 配置文件......会遇到 redis-cache。

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@EnableJpaRepositories(basePackageClasses =
        {com.mystuff1.MyJpaRepository1.class, com.mystuff2.MyJpaRepository2.class})
@Configuration
/* jpa:repositories (di.xml) does not support being wrapped in a spring-profile-attributed-bean.  this class is a workaround */
/* we only want InternalFhirBundleProviderWrapperJpaRepository "scanned in" as a JpaRepository .. when the spring-profile of "default" is specified.  */
@Profile("default")
public class JpaReposInASpecificSpringProfileVoodooWhereWaldoJavaConfig {
}
于 2021-04-05T20:36:09.230 回答