简体   繁体   中英

Is it possible to change at runtime a specific value inside a property.file in spring boot?

I'm developing an API which will connect with several endpoints. The uri for each endpoint is something like this:

rest/services/General/directory1/MapServer/export
rest/services/General/directory2/MapServer/export
rest/services/General/directory3/MapServer/export
rest/services/General/directory4/MapServer/export

and so on...

I don't know if it's possible, but would like to have something like this instead:

rest/services/General/${value}/MapServer/export

and then on my code just call the endpoint above injecting the specific directory that I want on ${value}

Is it possible? Don't know what I'm missing as I googled but couldn't find anything related.

Cheers

You can do so by means of Spring Cloud Config.

Spring Cloud Config provides server and client-side support for externalized configuration in a distributed system. With the Config Server you have a central place to manage external properties for applications across all environments. The concepts on both client and server map identically to the Spring Environment and PropertySource abstractions, so they fit very well with Spring applications, but can be used with any application running in any language. As an application moves through the deployment pipeline from dev to test and into production you can manage the configuration between those environments and be certain that applications have everything they need to run when they migrate. The default implementation of the server storage backend uses git so it easily supports labelled versions of configuration environments, as well as being accessible to a wide range of tooling for managing the content. It is easy to add alternative implementations and plug them in with Spring configuration.

For more details, kindly go through spring documentation here .

I solve the problem using the simplest approach possible. In my code I used the string.replace() method. Was looking for something more robust, but as it was taking lots of time to sort it out how to do it, I decided to go with the string.replace method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM