如何检查JHipster环境

如何检查JHipster环境,jhipster,Jhipster,有人能告诉我这是使用JHipster检查当前环境的正确方法吗 public DwollaService(ApplicationProperties applicationProperties, Environment env) throws Exception { this.dwolla = applicationProperties.dwolla; this.env = env; Collection<String> activeProfiles

有人能告诉我这是使用JHipster检查当前环境的正确方法吗

public DwollaService(ApplicationProperties applicationProperties, Environment env) throws Exception {
    this.dwolla = applicationProperties.dwolla;
    this.env = env;
    
    Collection<String> activeProfiles = Arrays.asList(env.getActiveProfiles());
    Boolean isProd = activeProfiles.contains(JHipsterConstants.SPRING_PROFILE_PRODUCTION);
    this.dwollaClient = new Dwolla(
        this.dwolla.getKey(),
        this.dwolla.getSecret(),
        (isProd) ? DwollaEnvironment.PRODUCTION : DwollaEnvironment.SANDBOX 
    );
}
publicDWollaservice(ApplicationProperties ApplicationProperties,Environment env)引发异常{
this.dwolla=applicationProperties.dwolla;
this.env=env;
集合activeProfiles=Arrays.asList(env.getActiveProfiles());
布尔值isProd=activeProfiles.contains(JHipsterConstants.SPRING\u PROFILE\u PRODUCTION);
this.dwollaClient=新的Dwolla(
this.dwolla.getKey(),
this.dwolla.getSecret(),
(isProd)?DwollaEnvironment.PRODUCTION:DwollaEnvironment.SANDBOX
);
}

您的代码可以工作,但以下是识别产品环境的更好方法(事实上,spring已弃用)


这是一种方法,是的,但通常我更喜欢避免将产品配置文件的概念与环境混为一谈,因为您可能希望在多个环境中运行产品配置文件(即阶段、鉴定、集成)。因此,我通常为每个环境定义另一个概要文件,以便application-prod.yml只包含所有环境通用的属性。这也取决于你在哪里储存秘密
isProd = env.acceptsProfiles(Profiles.of(JHipsterConstants.SPRING_PROFILE_PRODUCTION));