Spring @Value escape colon(:) in default value

后端 未结 2 2018
借酒劲吻你
借酒劲吻你 2020-12-15 15:37

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

@Value(\"${prop.url:http://myurl.co         


        
相关标签:
2条回答
  • 2020-12-15 15:46

    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'}")
    
    0 讨论(0)
  • 2020-12-15 16:03

    On Spring version 3.2 the default value works without quotes.

    0 讨论(0)
提交回复
热议问题