首页 > 解决方案 > 配置服务器数据源连接@RefreshScope

问题描述

我有一个配置服务器和几个客户端。

这是我的配置设置:

@Component
@RefreshScope
@ConfigurationProperties(prefix = "params")
public class ConfigParams {

    private Map<String, Map<String, String>> datasource;

    // here are some other properties not related to db
}

我也有spring.cloud.refresh.extra-refreshable=javax.sql.DataSource。因此,当更改某些配置参数时,将重新创建所有带有 @RefreshScope 的 bean(工作正常)。但即使数据源属性没有改变,与数据库的连接也会关闭和打开。那是糟糕的。

所以,我希望只有在相应的属性发生变化时才重新创建数据源 bean。不是每次。你能帮我吗?

我会很感激你的帮助。

标签: springspring-datadatasourcespring-cloudspring-cloud-config-server

解决方案


推荐阅读