springboot额外配置文件-@PropertySource

1.选择需要读取的额外配置文件(application.yml这个不需要)@PropertySource和@Value,如下图

@Component
@PropertySource("classpath:abc.properties")
@ConfigurationProperties(prefix = "person")
@Data
public class Person {
    private String name;
    private Integer age;
    private boolean boos;
    private Date birth;
    private Map<String,Object> maps;
    private List<Object> list;
    private Dog dog;
Person(name=老王, age=20, boos=true, birth=Mon Jan 01 00:00:00 CST 2018, maps={k1=111, k2=kk2}, list=[zhangsan, lisi], dog=Dog(name=gou, age=2))

}

注意

@ConfigurationProperties(prefix = “person”)
扫描的是所有配置文件前缀是person的
如果多个配置文件前缀名相同,会出现覆盖或叠加
springboot额外配置文件-@PropertySource_第1张图片
springboot额外配置文件-@PropertySource_第2张图片

springboot额外配置文件-@PropertySource_第3张图片

你可能感兴趣的:(springboot)