多模块开发中每个模块都有自己的配置文件和配置类,可以通过以下几种方式引入:
- yml引入
-
配置文件方式:(每个springboot项目中都需要引入,对于springboot源配置并没有侵入性)
spring: profiles: include: es,db,kafkaconsumer
-
配置类方式:(以下方式可以在导入依赖自动加载,不需在配置文件中引入,但是侵入了springboot默认加载application文件的顺序,尤其是项目上线时,application配置文件外置自动加载无效)
/** * @author: hs * @Date: 2019/4/25 19:11 * @Description: 无需使用 include引入多个配置,缺点打包发布时,并不会按照springboot默认加载文件顺序来读取文件。 */ @Configuration @AutoConfigureOrder(1) public class YamlAutoConfig { @Bean public static PropertySourcesPlaceholderConfigurer properties() { PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean(); ClassPathResource dbYaml = new ClassPathRes