【问题标题】:How does Springboot use a database instead of a application.propertiesSpring Boot 如何使用数据库而不是 application.properties
【发布时间】:2020-06-02 12:09:07
【问题描述】:

我要实现的是springboot获取数据库中配置的属性值来完成自动配置。就像使用 application.properties 一样

【问题讨论】:

标签: java mysql database spring jdbc


【解决方案1】:

可以在启动时以编程方式覆盖 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);
 }
}

【讨论】:

  • springboot启动方法入口中如何进行数据库属性查询和覆盖设置
  • 这很大程度上取决于您使用什么数据库,以及属性如何保存在其中。您需要使用这些信息更新您的问题。但基本上这应该是关于在数据库中执行一个简单的查询
猜你喜欢
  • 1970-01-01
  • 2021-07-07
  • 1970-01-01
  • 2020-09-07
  • 2016-09-14
  • 2017-08-07
  • 2020-06-27
  • 2016-08-28
  • 1970-01-01
相关资源
最近更新 更多