PropertySource简介
SpringBoot中@Value和@ConfigurationProperties分别是调用application.yml和application.properties默认配置文件
不过我们想要配属性的话,肯定都不能全都往默认配置文件里堆的,如果想引用其它配置文件的属性值,就可以使用本博客介绍的@PropertySource注解
PropertySource使用方法
新建一个person.properties配置文件
person.last-name=李四
person.age=18
person.birth=2020/11/13
person.boss=false
person.maps.k1=v1
person.maps.k2=14
person.lists=a,b,c
person.dog.name=小狗
person.dog.age=2
使用@PropertySource(“classpath:person.properties”)获取对应的properties文件,再用@ConfigurationProperties(prefix = “person”)进行属性映射
@PropertySource(value = {"classpath:person.properties"})
@Component
@ConfigurationProperties(prefix = "person")
public class Person {
// @Value("${person.last-name}")
private String lastName;
//