@ConfigurationProperties 配置详解
前言 新的一年到了,在这里先祝大家新年快乐.我们在上一篇spring boot 源码解析12-servlet容器的建立 中 分析 ServerProperties时,发现其类上有@ConfigurationProperties 注解,加上该注解后,就会注入在application.properties中server开头的属性,那么它是怎么生效的呢?我们这篇文章就来分析一下.这篇文章内容比较长,大家慢慢看… @ConfigurationProperties 使用方式 我们首先声明实体类,用于属性的注入.代码如下: public class People { private String name; private Integer age; private List<String> address; private Phone phone; // get set 忽略,自己加上即可.. } public class Phone { private String number; // get set 忽略,自己加上即可.. } 在application.properties 中加入如下配置: com.example.demo.name=${aaa:hi} com.example.demo.age=11 com.example.demo.address[0]=北京 com.example