Spring @Value escape colon(:) in default value

a 夏天 提交于 2019-11-27 17:07:20

问题


I have the following property annotated with @Value. I have a default value defined using the default separator of ':"

@Value("${prop.url:http://myurl.com}")

Is there a way to escape the ':' in http://myurl.com or do I have to define a different separator value in my configuration.


回答1:


Update: For spring 4.2 and higher, no single quotes are needed. Spring will see the first colon as special, and use all the rest as a single string value.

For spring 4.2 and higher,

@Value("${prop.url:http://myurl.com}")

For the previous versions, I believe single quotes will do the trick:

@Value("${prop.url:'http://myurl.com'}")



回答2:


On Spring version 3.2 the default value works without quotes.



来源:https://stackoverflow.com/questions/31711308/spring-value-escape-colon-in-default-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!