Spring @Value转义冒号(:)为默认值 [英] Spring @Value escape colon(:) in default value
本文介绍了Spring @Value转义冒号(:)为默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下用@Value注释的属性.我有一个使用默认分隔符':"
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}")
是否可以在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.
推荐答案
更新: 对于4.2或更高版本的Spring,不需要单引号. Spring将第一个冒号视为特殊字符,并将其余所有都用作单个字符串值.
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.
对于4.2或更高版本的春季,
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'}")
这篇关于Spring @Value转义冒号(:)为默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文