Spring Boot加载配置文件
https://my.oschina.net/wangyuefive/blog/704615#h3_4
问题3:如何根据线上环境和线下环境加载不同的配置?如何加载多个配置文件?
1、Profiles:
Spring Profiles提供了一种隔离应用程序配置的方式,并让这些配置只能在特定的环境下生效。在配置文件中,用spring.profiles.active属性来指定特定环境的配置文件。在Spring Boot中多环境配置文件名需要满足application-{profile}.properties
的格式,其中{profile}
对应你的环境标识,比如:
application-dev.properties
:开发环境application-test.properties
:测试环境application-prod.properties
:生产环境
至于哪个具体的配置文件会被加载,需要在application.properties
文件中通过spring.profiles.active
属性来设置,其值对应{profile}
值。例如:
application.properties配置:spring.profiles.active = dev即指定application-dev.properties会被加载。
2、通过启动参数指定运行环境。
通过命令行启动:
java -jar xxxxx.jar --spring.profiles.active=prod。
上述指定为prod环境,则spring application会自动根据application-{profile}.properties的格式找到application-prod.properties文件加载。
3、加载多个自定义文件。
例如:
spring.profiles.active = dev,database
等于告诉Spring Boot加载application-dev.properties和application-database.properties文件,从而实现多个配置文件的加载。
四种读取properties文件的方式
http://www.imooc.com/article/18252
集成Mybatis
http://www.imooc.com/article/15406
开启定时任务
http://www.imooc.com/article/15612
spring-boot上传文件MultiPartFile获取不到文件问题解决
http://blog.csdn.net/happy_cheng/article/details/54178392
Spring boot上传文件时MultipartFile为空问题
http://blog.csdn.net/tanga842428/article/details/72773773
spring boot默认日志配置,以及改用log4j日志配置学习使用排出多余的依赖
http://blog.csdn.net/yanweihpu/article/details/54139382
http://blog.csdn.net/loongshawn/article/details/50951329