Assign a value to a parameter in application properties before use

Rajeev Ranjan picture Rajeev Ranjan · Nov 15, 2017 · Viewed 8.4k times · Source

I have a property in my application.properties file in a SpringBoot project -

app.module.service.url=http://localhost:8090/{DOCID}

I have injected it into my Java file as below -

@Value("${app.module.service.url}")
private String url;

Now I need to replace DOCID with some value in my function(i.e-dynamic). How do I get to do this or am I completely missing it? I am aware that we can do this in case of message properties in Spring. But here I have nothing to do with Locales.

Edit:

There is some value which I need to put in place of {DOCID} when using it within my Java implementation.

...
public class Sample{

@Value("${app.module.service.url}")
private String url;

public void sampleFunc(){

String str = "random Value" //some dynamic value goes in here
...

Now I need to replace {DOCID} with str in url

Answer

Pramod S. Nikam picture Pramod S. Nikam · Nov 15, 2017

Two way binding is not possible in Spring Properties.It can only read run time and environmental variables.

Please refer following link for more information.

https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-Configuration-Binding