I'd like to set active profile for Spring based on environment variable. To do so, I've written the following code:
@Configuration
public class SpringBootApplicationInitializer
implements ServletContextInitializer {
@Override
public void onStartup(ServletContext servletContext) {
String platform = System.getProperty("platform");
if ("prod".equals(platform)) {
servletContext.setInitParameter("spring.profiles.active",
"prod");
} else if ("stag".equals(platform)) {
servletContext.setInitParameter("spring.profiles.active",
"stag");
} else {
servletContext.setInitParameter("spring.profiles.active",
"dev");
}
}
}
This code gets executed, however, no profile is set as Spring writes: INFO - No active profile set, falling back to default profiles: default
How do I achieve what I want?