If you are using Spring in a command-line program, you likely have a main class that looks something like this:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).run(args);
}
}
You can specify active profiles by calling the profiles()
method:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class)
.profiles("myprofile", "otherprofile")
.run(args);
}
}
If you are using Spring in a Servlet Container, you likely have a Servlet Initializer that looks something like this:
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
You can specify active profiles by calling the profiles()
method:
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class)
.profiles("myprofile", "otherprofile");
}
}
You can of course write code to dynamically determine which profiles to activate.