Instead of using a custom condition, you can use the Spring profile, which is only allowed when using the built-in container. When you deploy the Spring boot application to Tomcat, its main method does not start, which makes it a good place to include the profile that you only want to be active in the built-in case.
Something like that:
@SpringBootApplication
public class So34924050Application extends SpringBootServletInitializer {
@Bean
@Profile("embedded")
public EmbeddedOnlyBean embeddedOnlyBean() {
return new EmbeddedOnlyBean();
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(So34924050Application.class);
}
public static void main(String[] args) {
new SpringApplicationBuilder(So34924050Application.class).profiles("embedded").run(args);
}
}
source
share