application.properties,用来配置一些可以手动修改而且不用编译的变量,这样的作用在于,打成war包或者jar包用于生产环境时,我们可以手动修改环境变量而不用再重新编译。
spring boo默认已经配置了很多环境变量,例如,tomcat的默认端口是8080,项目的contextpath是“/”等等(更多请看https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config)
spring boot允许你自定义一个application.properties文件,然后放在以下的地方,来重写spring boot的环境变量或者定义你自己环境变量 1.当前目录的 “/config”的子目录下 2. 当前目录下 3.** classpath根目录的“/config**”包下 4. classpath的根目录下
其中1、2点适合在生产环境下,例如,打包成可执行的jar包 
注意,“当前目录”是指demo.jar包的目录下,要使配置文件生效,在使用java -jar demo.jar的命令时,必须先路由到demo.jar包的路径下,再使用其命名 
另外,3、4点适合在开发环境下

如果同时在四个地方都有配置文件,配置文件的优先级是从1到4。
使用配置文件之后,spring boot启动时,会自动把配置信息读取到spring容器中,并覆盖spring boot的默认配置,那么,我们怎么来读取和设置这些配置信息呢
1.通过命令行来重写和配置环境变量,优先级最高,例如可以通过下面的命令来重写spring boot 内嵌tomcat的服务端口,注意“=”俩边不要有空格
java -jar demo.jar --server.port=9000
2.通过**@value**注解来读取
1@RestController 2@RequestMapping("/task") 3public class TaskController { 4 5 @Value("${connection.remoteAddress}") private String address; 6 7 @RequestMapping(value = {"/",""}) 8 public String hellTask(@Value("${connection.username}")String name){ 9 return "hello task !!"; 10 } 11}
3. 自定义工具栏
1@Component 2public class SystemConfig { 3 4 private static Properties props ; 5 6 public SystemConfig(){ 7 try { 8 Resource resource = new ClassPathResource("/application.properties");// 9 props = PropertiesLoaderUtils.loadProperties(resource); 10 } catch (IOException e) { 11 e.printStackTrace(); 12 } 13 } 14 15 16 /** 17 * 获取属性 18 * @param key 19 * @return 20 */ 21 public static String getProperty(String key){ 22 23 return props == null ? null : props.getProperty(key); 24 25 } 26 27 /** 28 * 获取属性 29 * @param key 属性key 30 * @param defaultValue 属性value 31 * @return 32 */ 33 public static String getProperty(String key,String defaultValue){ 34 35 return props == null ? null : props.getProperty(key, defaultValue); 36 37 } 38 39 /** 40 * 获取properyies属性 41 * @return 42 */ 43 public static Properties getProperties(){ 44 return props; 45 } 46 47} 48 49//用的话,就直接这样子 50String value = SystemConfig.getProperty("key");