1

I'm tried to call a get http response with spring boot, and I have a value of url in application.properties, I'm tried to call this value in annotation @GetMapping like that :

@GetMapping("${service.url}")

But Spring boot says "Cannot resolve @PathVariable service.url"

Maybe there are another way to get this value ?

Thanks for your help everyone.

Charles
  • 11
  • 1
  • 4
    I might be wrong, but IMHO those values can be only either raw string value or a constant – Marek May 03 '21 at 10:55

2 Answers2

1

Try using SpEL. In your case, this can be modelled as something like

@GetMapping("#{'${service.url}'}")
susheem_k
  • 136
  • 1
  • 4
  • Thanks but it's the same , Cannot resolve @PathVariable service.url" How can I do with a constant variable ? – Charles May 03 '21 at 12:07
  • That is just a warning from your IDE though. The application should still be working as expected although your IDE is just telling you that your URI has a `Path Variable` which you are not resolving/reading in your method definition. Any specific reason for reading the path URI from the properties file? – susheem_k May 03 '21 at 17:15
0

In your Controller class, you can pass an object of type org.springframework.core.env.Environment in the constructor, e.g. named env.

Then you can just call

@GetMapping("${env.getRequiredProperty("service.url")}")
nulldroid
  • 1,150
  • 8
  • 15