I need to save the configuration of the Spring Boot application in the database.
Is it possible to store the database information in the application.properties and use them to connect to the database and retrieve all the other properties from there?
So my application.properties would look like:
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=mydb spring.datasource.username=user spring.datasource.password=123456 spring.jpa.database-platform=org.hibernate.dialect.SQLServer2012Dialect And the other configuration would be fetched from the database with something like this:
@Configuration @PropertySource(value = {"classpath:application.properties"}) public class ConfigurationPropertySource { private final ConfigurationRepository configurationRepository; @Autowired public ConfigurationPropertySource(ConfigurationRepository configurationRepository) { this.configurationRepository = configurationRepository; } public String getValue(String key) { ApplicationConfiguration configuration = configurationRepository.findOne(key); return configuration.getValue(); } } With ApplicationConfiguration as an Entity.
But Spring Boot does not get the configuration from the database.
application.properties. And I can connect to the database and save Entities. But the properties from the database are not loaded.spring.jpa.show-sql=trueis saved in the database (along with other properties). If I set this property in theapplication.propertiesfile it works fine, but if I put it in the database it has no effect on Spring Boot.application.propertiesfile?