I have a spring REST application, which works fine if ran using mvn exec with embedded tomcat (beans get created fine, @Autowired works as expected, etc.).
If, however, I create a WAR using mvn package and deploy it into an existing tomcat, some bean creator functions do not get called.
For example, I have a bean creator function
@Bean @Autowired public ObjectMapper objectMapper(LocalizedMessages messages) { // create and configure ObjectMapper with custom serializer } Which gets called when with an embedded tomcat, and does not get called when using war. I tried to add the containing class to the SpringApplicationBuilder's sources, but that did not have any effect.
Does anyone have a suggestion how I could get the war version to work properly?
Some extra details
I am using spring-boot 1.2 with the spring-boot-starter-web maven dependency, and originally I was using an App class with a main function to create and start a new SpringApplication (which in turn started an embedded tomcat), and also the App class has appropriate @ComponentScan and @EnableAutoConfiguration annotations so that all @Components and @Configurations are appropriately handled.
With the war packaging, I created a class that extends SpringBootServletInitializer and has a @SpringBootApplication annotation that adds the above App.class to the SpringApplicationBuilder's source list (see generating a working war file with maven for a spring-boot web application). I even tried to list all @Components among the sources, but the above mentioned bean creator functions are still not called.
<context:component-scan/>, *<mvc:annotation-driven/>` or something alike in the war's application context?