spring-boot without @SpringBootApplication

Refresh

November 2018

Views

4.1k time

2

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.

1 answers

9

@SpringBootApplicationявляется альтернативой для @Configuration, @EnableAutoConfigurationи @ComponentScan.

Возможно , вы хотите использовать @Configuration+ @ComponentScan. Если вы хотите конфигурации загрузки XML вы можете использовать: @ImportResourceаннотацию.

Если вы хотите использовать автонастройку, но вы можете отключить несколько авто конфигураций, например: @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

Подробности: