Spring Boot 注入配置 在组件中引用 1 2 3 4 5@Component public class ... { @Value("${配置键}") // 要配置的变量 } 如: 1 2 3 4 5 6 7aaa: bbb: ccc: 1 ddd: - a - b - c 1 2 3 4 5@Component public class ... { @Value("${aaa.bbb.ccc}") Integer cccVal; } 不能作用于集合。 在类上引用 1 2 3 4 5@Component @ConfigurationProperties(prefix="配置键") public class ... { // 要配置的变量,名称与配置键下的各键的名称一样 } 如上例: 1 2 3 4 5 6 7 8@Component @ConfigurationProperties(prefix="aaa.bbb") public class ... { Integer ccc; List<String> ddd; }