How to check JHipster environment

Viewed 73

Can someone tell me if this is the correct way to check the current environment when using 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 
    );
}
1 Answers

Your code works but following is the better way to identify prod environment(In fact spring deprecated checking active profiles based on strings).

isProd = env.acceptsProfiles(Profiles.of(JHipsterConstants.SPRING_PROFILE_PRODUCTION));
Related