Spring @Value escape colon(:) in default value

2019-02-07 17:46发布

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条回答
Lonely孤独者°
2楼-- · 2019-02-07 18:00

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'}")
查看更多
登录 后发表回答