Java 如何将yml配置里的LIst
1.引入依赖
org.springframework.boot spring-boot-configuration-processortrue
2. yml 配置文件中的配置格式应为
test: students: - name: "duan" age: "别问,问就是18" gender: "男"
- name: "帅哥" age: "17" gender: "男"
3.java 注入方式;
import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; import java.util.List; @Configuration @ConfigurationProperties(prefix = "test",ignoreInvalidFields = true) @Data public class CertManagerItemsConfig { Liststudents; }
注意: prefix 对应的 test 一定要写对,
students 对应的二级 students;
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)