我想要实现的是springboot获取数据库中配置的属性值来完成自动配置。就像使用 application.properties 一样
最佳答案
可以在启动时以编程方式覆盖 Spring 属性。这将是从您希望的任何数据库中检索属性并设置它们的好地方。
这是一个示例(从 this answer 复制/粘贴)。您必须添加从数据库获取配置
@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);
}
}
关于java - Spring Boot 如何使用数据库而不是 application.properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60281439/