Spring Boot Programmatically setting profiles
You can set additional profiles on start up:
SpringApplication springApp = new SpringApplication(Main.class);
springApp.setAdditionalProfiles("profile1", "profile2");
springApp.run(args);
Another way of doing it in Spring Boot 2 is by using SpringApplicationBuilder
:
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
@SpringBootApplication
public class MySpringProgram {
public static void main(String[] args) {
new SpringApplicationBuilder(MySpringProgram.class)
.profiles("profile1", "profile2")
.run(args);
}
}
I also had the same problem and after struggling for half a day I ended up with this:
@SpringBootApplication
public class MyApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, "dev");
SpringApplication.run(MyApplication.class, args);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, "dev");
super.onStartup(servletContext);
}
}