其他分享
首页 > 其他分享> > 没有@SpringBootApplication的spring-boot

没有@SpringBootApplication的spring-boot

作者:互联网

我正在尝试将spring,non-boot应用程序迁移到启动应用程序.当前的一个构建一个war文件.按照these的说明,我正在完成迁移步骤.

我发现@SpringBootApplication注释强迫很多事情失败.例如,当我确实需要现有的xml安全配置保持不变时,它会尝试自动配置安全性.我发现我可以覆盖@EnableAutoConfiguration并排除配置类(.i.e.SecurityAutoConfiguration.class).但我发现它对我已经在我的类路径上的项目做了很多.我决定最好删除@SpringBootApplication并将其替换为@Configuration,@ ComponentScan和@ImportResource以加载我的原始上下文xml.该类扩展了SpringBootServletInitializer,以便我可以注册我的自定义servlet和过滤器.

我发现,它现在不再知道加载application.yml或bootstrap.yml.是什么触发了这些文件的自动配置?我是否会回退加载传统的属性占位符配置器?我想避免这种情况,因为下一步是将其连接到spring cloud config以集中管理应用程序配置.

解决方法:

@SpringBootApplication是@ Configuration,@ EnableAutoConfiguration和@ComponentScan的替代品.

可能你想使用@Configuration @ComponentScan.如果要加载xml配置,可以使用:@ImportResource注释.

如果要使用自动配置,但可以禁用一些自动配置,例如:

@EnableAutoConfiguration(排除= {DataSourceAutoConfiguration.class})

细节:

> 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

标签:spring,spring-boot-2
来源: https://codeday.me/bug/20190717/1488781.html