Spring Cloud Config更改后切换jdbc连接(Switch jdbc connection after Spring Cloud Config change)

编程入门 行业动态 更新时间:2024-10-25 18:25:29
Spring Cloud Config更改后切换jdbc连接(Switch jdbc connection after Spring Cloud Config change)

在成功设置了云配置服务器并确认所有功能都按预期运行后,我遇到了这个问题,但我不确定它是否受支持或最佳路径。

我们遵循数据库每服务模式,因此我进行了一个实验,我提交了一个包含每个服务的数据库连接详细信息的dev和staging文件,以便如果需要更改服务器地址和凭证,我们只需要在配置回购。

我已经正确设置了这一点,并确认这些更改确实从配置服务器传播到客户端。

只有在做完所有这些之后,我才注意到即使服务获得了更新的数据库详细信息,它也不会切换其连接。

这可能吗? 我能做到这一点的唯一方法就是如果我重新启动了服务,而且这种做法已经失去了实现所有这一切的目的。 我尝试了连接超时,但它没有帮助。 该服务仍然连接到以前的连接。

After successfully setting up a cloud config server and confirming that all works as expected I ran into this issue but I'm not sure if it's supported or the best way to go.

We follow the database-per-service pattern so as an experiment I committed a dev and staging file containing the db connection details of each service so that if we needed to make changes to the server address and credentials we only needed to do it in the config repo.

I have set this up correctly and I confirm that the changes are indeed being propagated from the config server to the clients.

It was only after doing all of this did I notice that even though the services got the updated database details it DID NOT switch its connection.

Is this possible? The only way I could do this was if I restarted the service and that kinda defeats the purpose of having all of this in place. I tried toying with the connection timeouts but it didn't help. The service was still connected to the previous connection.

最满意答案

所以它看起来简单的添加了@RefreshScope到我的控制器中。 感谢Spring的David Syer的洞察力。

So it appears a simple addition of the @RefreshScope to my controller did the trick. Thanks to Spring's David Syer for the insight.

更多推荐

本文发布于:2023-08-07 14:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464893.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Config   Cloud   Spring   jdbc   change

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!