如何将包含Pojos的Map对象绑定到yaml文件?

问题描述 投票:0回答:1

在spring-boot / spring-cloud应用程序中,我想将Map对象绑定到我的application.yml,但我有一个“Elements ... where lef unbound error”。

在我的名为Ebox的类中,我想绑定一个名为infosTenants的映射,由字符串标识并包含InfosTenant类型的值。

在我的application.yml下面(没有每个类或子类的getter / setter)

@ConfigurationProperties(prefix = "application", ignoreUnknownFields = false)
public class ApplicationProperties {

    private Ebox ebox = new Ebox();

    public ApplicationProperties() {
    }

    // getters/setters ...

    public static class Ebox {
        private String authUrl;
        private Map<String, InfosTenant> infosTenants = new HashMap<>();

        public Ebox() {
        }

        public class InfosTenant{

            private String clientId="";
            private String clientSecret="";

            public InfosTenant() {
            }
            // getters/setters ...

        }
    }
}

在我的application.yml中,我在租户地图中定义了一个租户,由关键租户1标识。

application:
    ebox:
        auth-url: https://oauth-server/api/oauth/token
        infos-tenants:
            tenant1:
                client-id: myclient
                client-secret: secret

但是,信息租户下的所有价值都没有受到限制。有人有想法吗?谢谢

java spring-boot yaml spring-cloud-config
1个回答
0
投票

我发现了我的错误,内部类应该是静态的,我忘记了类InosTenant之前的静态。

public static class InfosTenant{

        private String clientId="";
        private String clientSecret="";

        public InfosTenant() {
        }
        // getters/setters ...

    }
© www.soinside.com 2019 - 2024. All rights reserved.