On my spring boot application I want to override just one of my @Configuration classes with a test configuration (in particular my @EnableAuthorizationSer
I recently had to create a dev version of our application, that should run with dev active profile out of the box without any command line args. I solved it with adding this one class as a new entry, which sets the active profile programmatically:
package ...;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.StandardEnvironment;
@Import(OriginalApplication.class)
public class DevelopmentApplication {
public static void main(String[] args) {
SpringApplication application =
new SpringApplication(DevelopmentApplication.class);
ConfigurableEnvironment environment = new StandardEnvironment();
environment.setActiveProfiles("dev");
application.setEnvironment(environment);
application.run(args);
}
}
See Spring Boot Profiles Example by Arvind Rai for more details.