初识spring boot maven管理--属性文件配置

在使用springboot的时候可以使用属性文件配置对属性值进行动态配置,官方文档原文如下:

Spring Boot uses a very particular PropertySource order that is designed to allow sensible overriding of values, properties are considered in the the following order:

  1. Command line arguments.
  2. Java System properties (System.getProperties()).
  3. OS environment variables.
  4. @PropertySource annotations on your @Configuration classes.
  5. Application properties outside of your packaged jar (application.properties including YAML and profile variants).
  6. Application properties packaged inside your jar (application.properties including YAML and profile variants).
  7. Default properties (specified using SpringApplication.setDefaultProperties).
英语不太好,大概的意思是:springboot将会使用指定的PropertySource加载顺序加载属性文件,此目的是为了可以动态赋值!下面是顺序关系:
1、命令行参数
2、java的系统属性文件
3、OS环境变量
4、使用@PropertySource 
5、在jar包外的application.properties
6、在jar包内的application.properties(位置在src目录下)
7、编码指定的位置 使用SpringApplication.setDefaultProperties方法

如果觉得不准确,请更正,谢谢!

属性文件配置好之后就可以在属性中使用
@Value("${name}")
private String name;
 name的值将根据properties文件进行动态赋值!







初识spring boot maven管理--属性文件配置,布布扣,bubuko.com

初识spring boot maven管理--属性文件配置

上一篇:【学习-水滴石穿】 JavaScript用arguments对象访问函数的参数


下一篇:使用VC++2013写出短小精悍的函数