如何将Spring云配置值绑定到@ConfigurationProperties对象? [英] How to bind Spring cloud config values to @ConfigurationProperties object?

查看:190
本文介绍了如何将Spring云配置值绑定到@ConfigurationProperties对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用云配置服务器(特别是Jhipster注册表)上yaml文件中的属性填充@ConfigurationProperties注释的类.

应用程序正在连接到服务器并读取正确的文件,因为当服务器或文件不可用时,我会因缺少主机或意外的空文件而出现异常.

但是,我无法访问文件中的任何属性.

我主要是尝试填充@ConfigurationProperties对象,但是所有字段均为空.

此外,由于找不到属性占位符,尝试对文件中的任何属性使用@Value都会引发错误.

我已经设置了spring.cloud.config.nameprofile值,以匹配预期的格式解决方案

该问题原来是错误的配置,通过从云配置bootstrap.yml中指定的应用程序名称中删除了所有特殊字符,解决了该问题. /p>

I am trying to populate a @ConfigurationProperties-annotated class with properties from a yaml file on my cloud config server (Jhipster registry, specifically).

The application is connecting to the server and reading the correct file, as when either the server or the file is unavailable, I get an exception either for the missing host or an unexpected empty file.

However, I cannot access any of the properties in the file.

I am primarily trying to populate a @ConfigurationProperties object, but all of the fields are null.

Additionally, trying to use @Value for any of the properties in the file throws an error as the property placeholders aren't found.

I've set the spring.cloud.config.name and profile values to match the format expected according to the JHipster docs.

解决方案

The issue turned out to be an erroneous configuration, the problem was resolved by removing all special characters from the application name specified in the cloud config bootstrap.yml.

这篇关于如何将Spring云配置值绑定到@ConfigurationProperties对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆