Home » Java » java – How does Springboot use a database instead of a application.properties-Exceptionshub

java – How does Springboot use a database instead of a application.properties-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I want to achieve is that springboot gets the property values configured in the database to complete the automatic configuration. Just like using application.properties

How to&Answers:

It is possible to programatically override Spring properties at startup. This would be a good place to retrieve the properties from any database that you whish and set them.

Here is an example (copy/pasted from this answer) . You would have to add getting the configuration from the database

@SpringBootApplication
public class Demo40Application{
  public static void main(String[] args){
    SpringApplication application = new SpringApplication(Demo40Application.class);

    Properties properties = new Properties();
    properties.put("server.port", 9999);
    application.setDefaultProperties(properties);

    application.run(args);
 }
}