Spring Boot 中的配置文件有两种格式,properties 或者 yaml,通常状况下,二者能够任意使用,可是他们仍是有一些本质上的区别的,本文主要介绍yaml 配置,最后再来看看 yaml 和 properties 配置文件的区别java
1.项目根目录下的config目录中redis
2.项目根目录下spring
3. Classpath中的config数组
4. classpathbash
四个位置中的 application.yaml 文件的优先级按照上面列出的顺序依次下降。即若是有同一个属性在四个文件中都出现了,优先级高的为准。同时,开发者能够本身指定yaml文件的名字,可是若是自定义以后,须要指定配置文件的位置app
Yaml也支持数组注入,例如ide
my:
servers:
- my1.example.com
- my2.example.com复制代码
@ConfigurationProperties(prefix="my")
@Component
public class Config {
private List<String> servers = new ArrayList<String>();
public List<String> getServers() {
return this.servers;
}
}复制代码
redis:
redisConfigs:
- host: 192.168.66.1
port: 1111
- host: 192.168.0.10
port: 1111
复制代码
@Component
@ConfigurationProperties(prefix = "redis")
public class MyRedis {
private List<SingleRedisConfig> redisConfigs;
}复制代码
本人创业团队产品MadPecker,主要作BUG管理、测试管理、应用分发测试
网址:www.madpecker.com,有须要的朋友欢迎试用、体验! ui
本文为MadPecker技术人员编写,转载请标明出处this