springboot 默认读取application.properties,其他配置文件需要自己在启动参数添加
--spring.config.name=example
// 类路径
--spring.config.location=classpath:cong/example.properties
// file目录 多个用逗号隔开
--spring.config.location=classpath:cong/example.properties,file:E:/example.properties
通过启动参数指定profile
--spring.profiles.active=test
application-{profile}.properties中配置各个环境不同的内容
application-dev.properties
jdbc.url=jdbc:mysql://127.0.0.1/spring_dev
application-test.properties
jdbc.url=jdbc:mysql://127.0.0.1/spring_test
控制bean创建:
@Bean
@Profile("dev")