'How to remove the property values in application.properties and set them dynamically in Spring boot? [duplicate]

My application.properties file looks like this

#jwt
app.jwt.secret=RandomSecretKey
#1 day
app.jwt.expiration-in-ms=86400000
app.jwt.token.prefix=Bearer
app.jwt.header.string=Authorization

[email protected]
spring.mail.host=smtpout.asia.secureserver.net
spring.mail.port=465
spring.mail.protocol=smtps
[email protected]
spring.mail.password=******
spring.mail.properties.mail.transport.protocol=smtps
spring.mail.properties.mail.smtps.auth=true
spring.mail.properties.mail.smtps.starttls.enable=true
spring.mail.properties.mail.smtps.timeout=8000

I want to remove them from this file and set them by retrieving the values from database using JPA repositories. How to do this?



Solution 1:[1]

You can use consul.io to store and get your properties.

So if you use consul it's possible update the properties values at runtime using the annotation @RefreshScope

Example: https://www.baeldung.com/spring-cloud-consul

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Érico Monteiro