• <i id='HsZN2'><tr id='HsZN2'><dt id='HsZN2'><q id='HsZN2'><span id='HsZN2'><b id='HsZN2'><form id='HsZN2'><ins id='HsZN2'></ins><ul id='HsZN2'></ul><sub id='HsZN2'></sub></form><legend id='HsZN2'></legend><bdo id='HsZN2'><pre id='HsZN2'><center id='HsZN2'></center></pre></bdo></b><th id='HsZN2'></th></span></q></dt></tr></i><div id='HsZN2'><tfoot id='HsZN2'></tfoot><dl id='HsZN2'><fieldset id='HsZN2'></fieldset></dl></div>

      <tfoot id='HsZN2'></tfoot>

      <small id='HsZN2'></small><noframes id='HsZN2'>

      • <bdo id='HsZN2'></bdo><ul id='HsZN2'></ul>

        <legend id='HsZN2'><style id='HsZN2'><dir id='HsZN2'><q id='HsZN2'></q></dir></style></legend>

        Spring Boot + Yaml + @PropertySource + @ConfigurationProperti

        时间:2023-09-26
        <tfoot id='hNrzy'></tfoot>

        • <small id='hNrzy'></small><noframes id='hNrzy'>

          <i id='hNrzy'><tr id='hNrzy'><dt id='hNrzy'><q id='hNrzy'><span id='hNrzy'><b id='hNrzy'><form id='hNrzy'><ins id='hNrzy'></ins><ul id='hNrzy'></ul><sub id='hNrzy'></sub></form><legend id='hNrzy'></legend><bdo id='hNrzy'><pre id='hNrzy'><center id='hNrzy'></center></pre></bdo></b><th id='hNrzy'></th></span></q></dt></tr></i><div id='hNrzy'><tfoot id='hNrzy'></tfoot><dl id='hNrzy'><fieldset id='hNrzy'></fieldset></dl></div>

        • <legend id='hNrzy'><style id='hNrzy'><dir id='hNrzy'><q id='hNrzy'></q></dir></style></legend>
              <bdo id='hNrzy'></bdo><ul id='hNrzy'></ul>

                    <tbody id='hNrzy'></tbody>
                1. 本文介绍了Spring Boot + Yaml + @PropertySource + @ConfigurationProperties + 属性源文件中的列表未注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用 @ConfigurationPropertiesexternal.yml 属性注入 POJO,并使用 导入我的 external.yml 文件>@PropertySource.所有其他都被注入到 POJO 中,但不是一个复杂的列表.

                  I'm trying to inject external.yml properties into a POJO using @ConfigurationProperties and importing my external.yml file using @PropertySource. All other were injected into POJO but not a complex list.

                  一个.我尝试将 @NestedConfigurationProperty 用于复杂列表和地图.湾.我尝试将复杂的 POJO 作为内部静态和外部类.C.尝试了 @EnableConfigurationProperties 注释.等等

                  a. I tried using @NestedConfigurationProperty for the complex list and map. b. I tried complex POJO as inner static and outer class. c. Tried @EnableConfigurationProperties annotation. etc

                  ExternalProp.java
                  
                     @Component
                     @PropertySource(value = "classpath:external.yml", encoding = "UTF-8")
                     @ConfigurationProperties
                  
                     @Data
                     public class ExternalProp {
                  
                      private String bla;
                      private List<Person> persons;
                      private List<String> other;
                  
                      @Data
                      public static class Person {
                  
                          private int age;
                          private String name;
                          private Map<String, String> args;
                      }
                  
                  }
                  
                  

                  external.yml
                  
                     bla: bkdfjgkdf
                     persons:
                     -  age: 12
                        name: bla1
                        args:
                          a0: a0dev
                          a1: a1dev
                          a2: a2dev
                     -  age: 12
                        name: bla2
                        args:
                          b0: b0dev
                          b1: b1dev
                          b2: b2dev
                     strings: bla, bla1
                  
                  

                  bla: bkdfjgkdfstrings: bla, bla1 已正确注入,但未注入人员.我在哪里犯错了.

                  bla: bkdfjgkdf and strings: bla, bla1 have been injected properly but not persons. Where am I making mistake.

                  同样的 persons 对象复制到 application.yml 文件,然后,BOOM,正确获取值.

                  And same persons object copied to application.yml file, then, BOOM, getting values properly.

                  我期待一个包含一些地图 args 的人员列表.

                  I'm expecting a List of Persons which is having some Map args.

                  推荐答案

                  我相信这与你的 yml 格式有关.试试这个

                  I believe it has to do with your yml formatting. try this

                  external.yml
                  
                     bla: bkdfjgkdf
                     persons:
                        -  age: 12
                           name: bla1
                           args:
                             a0: a0dev
                             a1: a1dev
                             a2: a2dev
                        -  age: 12
                           name: bla2
                           args:
                             b0: b0dev
                             b1: b1dev
                             b2: b2dev
                     strings: bla, bla1
                  

                  这篇关于Spring Boot + Yaml + @PropertySource + @ConfigurationProperties + 属性源文件中的列表未注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:获取 YAML 路径下的所有节点 下一篇:Java 类在 Jar 中读取 Yaml

                  相关文章

                  最新文章

                2. <i id='sEk2w'><tr id='sEk2w'><dt id='sEk2w'><q id='sEk2w'><span id='sEk2w'><b id='sEk2w'><form id='sEk2w'><ins id='sEk2w'></ins><ul id='sEk2w'></ul><sub id='sEk2w'></sub></form><legend id='sEk2w'></legend><bdo id='sEk2w'><pre id='sEk2w'><center id='sEk2w'></center></pre></bdo></b><th id='sEk2w'></th></span></q></dt></tr></i><div id='sEk2w'><tfoot id='sEk2w'></tfoot><dl id='sEk2w'><fieldset id='sEk2w'></fieldset></dl></div>

                      <small id='sEk2w'></small><noframes id='sEk2w'>

                    1. <tfoot id='sEk2w'></tfoot>
                        <bdo id='sEk2w'></bdo><ul id='sEk2w'></ul>
                      <legend id='sEk2w'><style id='sEk2w'><dir id='sEk2w'><q id='sEk2w'></q></dir></style></legend>