Last active
August 29, 2023 03:03
-
-
Save sandipchitale/09daa7435d29fa9f26f5b3cd8c00fd5e to your computer and use it in GitHub Desktop.
Set profile based on other profile #springboot #profile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class PreConfigDataEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered { | |
@Override | |
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { | |
PropertiesPropertySourceLoader propertiesPropertySourceLoader = new PropertiesPropertySourceLoader(); | |
try { | |
List<PropertySource<?>> propertySources = propertiesPropertySourceLoader.load("Config resource 'class path resource [application.properties]' via location 'optional:classpath:/'", | |
new ClassPathResource("/application.properties")); | |
propertySources.stream().forEach((PropertySource<?> propertySource) -> { | |
Object springProfilesActive = propertySource.getProperty("spring.profiles.active"); | |
if (springProfilesActive instanceof String springProfilesActiveString) { | |
StringUtils.commaDelimitedListToSet(springProfilesActiveString).stream().forEach((String profile) -> { | |
if ("india".equals(profile)) { | |
environment.addActiveProfile("hindi"); | |
} | |
if ("spain".equals(profile) || "mexico".equals(profile)) { | |
environment.addActiveProfile("spanish"); | |
} | |
}); | |
} | |
}); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
@Override | |
public int getOrder() { | |
return Ordered.HIGHEST_PRECEDENCE; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
org.springframework.boot.env.EnvironmentPostProcessor=sandipchitale.appevents.AppeventsApplication.PreConfigDataEnvironmentPostProcessor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment