Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring-boot without @SpringBootApplication

I am attempting to migrate a spring, non-boot, app to a boot app. The current one builds a war file. Following these instructions, I am walking through the steps to migrate.

I am finding that the @SpringBootApplication annotation forces a lot of things to fail. For instance, it tries to auto config security when I really need the existing xml security config to remain as is. I found that I can override @EnableAutoConfiguration and exclude configuration classes (.i.e. SecurityAutoConfiguration.class). But I am finding it is doing this a great deal for the items I already have on my classpath. I decided it would be better to remove @SpringBootApplication and replace it with just @Configuration, @ComponentScan and @ImportResource to load my original context xml. The class extends SpringBootServletInitializer so that I can register my custom servlets and filters.

What I have found, it now no longer knows to load the application.yml or bootstrap.yml. What triggers auto configuration of these files? Do I fall back to loading with the traditional properties placeholder configurers? I want to avoid this as the next step is to hook it up to spring cloud config to centralize the management of the application configuration.

like image 891
dmfrey Avatar asked Oct 22 '15 21:10

dmfrey


1 Answers

@SpringBootApplication is a alternative for @Configuration, @EnableAutoConfiguration and @ComponentScan.

Probably you want use @Configuration + @ComponentScan. If you want load xml configuration you can use: @ImportResource annotation.

If you want use autoconfiguration, but you can disable a few auto configurations, eg: @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

Details:

  • http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-auto-configuration.html
  • http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-configuration-classes.html
  • http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-using-springbootapplication-annotation.html
like image 197
krynio Avatar answered Oct 20 '22 23:10

krynio