I have a requirement where I get the DB URI, DB URL etc at runtime in JavaCode. This value needs to be available to application.properties for it to make a DB call.
I always used Spring boot to retrieve values assigned in application.properties file but not the other way How do I achieve something similar db.uri = {comingFromJavaCode}
Your question has already been answered in this stackoverflow thread. Write/Update properties file value in spring
By the way, the application.properties file is only read by the spring boot application once during startup. Adding any new values to the file at runtime has no effect. The following stackoverflow thread explains how to reload the application.properties file during loadtime. How can I reload properties file in Spring 4 using annotations? . This article can also be of use: https://docs.spring.io/spring/docs/3.2.6.RELEASE/javadoc-api/org/springframework/context/support/ReloadableResourceBundleMessageSource.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With