加载指定配置文件
1. @PropertySource 加载局部配置文件
@ConfigurationProperties 默认从全局配置文件(application.properties/application.yml)中获取值,
所有配置数据写在全局配置文件中,显得太臃肿了, 可将它们抽取出来,放到其他局部配置文件中。
@PropertySource :用于加载局部配置文件;
- 将 全局配置文件 中的emp相关配置数据 抽取 到 resources/ emp.properties 文件中
emp.properties
emp.last-name=李四
emp.age=30
emp.birthday=1989/9/12
emp.boss=false
emp.salary=23000
emp.map.key1=value1
emp.map.key2=value2
emp.list=one, two, three
emp.forte.name=python
emp.forte.time=3
- @PropertySource :加载指定的配置文件; value 属性是数组类型, 用于指定文件位置
@PropertySource(value = {"classpath:emp.properties"})
@Component
@ConfigurationProperties(prefix = "emp")
@Validated
public class Emp {
private String lastName;
private Integer age;
private Doub