M
M
mitaichik2020-02-13 11:59:07
Spring
mitaichik, 2020-02-13 11:59:07

How to reread settings after changing properties file?

Good afternoon.
Using Spring Boot

There is a @ConfigurationProperties class - with settings from the properties file.
Can I somehow make it so that when this properties file is changed, the settings in this class are updated automatically, without reloading the application?

I know that there is Spring Cloud Config, but I would like something simpler, I just changed the file, the settings were updated.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sergey, 2020-02-15
kuzmin @sergueik

mitaichik
@Vope
example from
collection of small and focused Spring tutorials

https://github.com/eugenp/tutorials/tree/master/sp...
works great
with minimal changes if there is no desire or ability to move from spring 4.x to 5 .x
we take the code, we screw it into our project, we
assemble it, we
plant it in the docker or we launch it locally, specifying the path to application.properties

docker run -v ${HOME}/Desktop/:/var/properties -p 8086:8080 basic-example

read what's there
curl http://localhost:8085/basic
Hello some value

change
sed -i 's|some value|some other value|' ~/Desktop/application.properties

we see how the spring restarted
oaccPropertiesConfiguration:
Reloading configuration. URL is file:/var/properties/application.properties
read again - changed
curl http://localhost:8085/basic
Hello some other value

A
Andrey Ryabov, 2020-02-14
@Vope

There is Spring Boot DevTools, but I'm not sure that it will work with the config, rather no than yes :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question