Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

assign values to application.properties file Spring boot

Tags:

spring-boot

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}

like image 855
Surya Jilludimudi Avatar asked Dec 06 '25 02:12

Surya Jilludimudi


1 Answers

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

like image 160
Maurice Avatar answered Dec 07 '25 17:12

Maurice



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!