SpringBoot 配置文件相关


1、SpringBoot的Jar配置文件放在外面的方式,通过命令指定文件(多个方式):
1> java -jar test.jar --spring.config.location=D:\config\test.properties ,文件路径可以是列表,逗号分隔
2> java -jar -Dspring.config.location=D:\config\test.properties test.jar 

2、启动时指定配置文件的后缀(配置文件在jar内的classes下,默认位置):
java -jar test.jar --spring.profiles.active=sit
指定文件名:
java -jar test.jar --spring.config.name=myproject

3、默认读取配置文件的顺序:

  1. 项目根目录\config\*.properties
  2. 项目根目录\*.properties
  3. 项目根目录\src\main\resources\config\*.properties,编译后的路径就是 xxx.jar\BOOT-INF\classes 下
  4. 项目根目录\src\main\resources\*.properties

注意,假如有多个同名文件,那么高级别的覆盖低级别的,并且保留不冲突的属性。

#####################################
官网列出的顺序:https://docs.spring.io/spring-boot/docs/1.2.2.RELEASE/reference/html/boot-features-external-config.html

  1. Command line arguments.
  2. JNDI attributes from java:comp/env.
  3. Java System properties (System.getProperties()).
  4. OS environment variables.
  5. A RandomValuePropertySource that only has properties in random.*.
  6. Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants)
  7. Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants)
  8. Application properties outside of your packaged jar (application.properties and YAML variants).
  9. Application properties packaged inside your jar (application.properties and YAML variants).
  10. @PropertySource annotations on your @Configuration classes.
  11. Default properties (specified using SpringApplication.setDefaultProperties).
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值