1

I've a URL property injected as @Value("http://log${RELEASE_NAME:}:1234"). I now want to change this such that if RELEASE_NAME is defined, the URL should be http://log-${RELEASE_NAME}:1234; if RELEASE_NAME is not defined, the URL should be http://log:1234.

What'd be the SPEL to do this? The challenge is to conditionally prepend -.

Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219
  • It is answered here: https://stackoverflow.com/questions/26916598/how-to-correctly-specify-a-default-value-in-the-spring-value-annotation – VinhNT Aug 22 '19 at 01:48
  • @VinhNT Apparently you didn't understand my question. – Abhijit Sarkar Aug 22 '19 at 01:50
  • With a value properties: @Value("${RELEASE_NAME?:}") private String propUrl; Then, your url can be like this: String myUrl = "http://log" + propUrl + ":1234" as the manual way, I know there is better way to inject it directly in propUrl but I will test it before comment again – VinhNT Aug 22 '19 at 02:06

0 Answers0