简体   繁体   English

使用spring-cloud-consul从领事读取空字符串

[英]Reading empty string from consul using spring-cloud-consul

I'm migrating from file based .properties file to consul based configuration in my spring application. 我正在从Spring应用程序中的基于文件的.properties文件迁移到基于领事的配置。 I'm using spring-cloud-consul. 我正在使用spring-cloud-conul。 Earlier in my property file I had a property like following 在我的财产文件中,我之前有一个财产,如下所示

test.key=

In spring application class corresponding field is like this 在spring应用类中对应的字段是这样的

@Value("${test.key:defaultVal}") private String testConsul;

In the runtime, the value of testConsul string is an empty string. 在运行时, testConsul字符串的值是一个空字符串。 But when using the consul, whenever I put key test.key without a value, in the runtime it gets resolved to a null . 但是,当使用领事时,每当我将键test.key不带值时,在运行时它将解析为null

Is there anyway I can pass an empty string value through consul ? 无论如何,我可以通过领事传递空字符串值吗?

This is the work around we're using. 这是我们正在使用的解决方法。 use a default value which is not exist 使用不存在的默认值

${no.such.key:}

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM