[seata]spring cloud kubenetes 动态配置服务 seata ConfigurationFactory.getInstance()未重新创建

2024-02-21 982 views
9

当spring.cloud.kubernetes.reload.strategy设置为restart_context时,如果配置发生变化,重新构建ApplicationContext时,不会重新创建Configuration实例,也就是 ConfigurationFactory.getInstance()返回值不变,

变化前: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@68699afc, started on Fri May 05 15:46:20 CST 2023, parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@7308ffff

变化后: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@1783b248, started on Fri May 05 15:48:24 CST 2023, parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@3a2954a9

报错: java.lang.IllegalStateException: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@68699afc has been closed already

有优化或者版本升级吗?

回答

6

不支持热更新热部署,单例已经构建好了

9

是的 就是因为单例的原因

2

Kubenetes集群下,可以通过spring.cloud.kubernetes.reload.strategy设为shutdown解决, 开发环境就无解了

0

这个我们看下有没有什么spring-cloud或spring-boot官方提供的event可以监听,以便我们将applicationContext更新

7

你用的是不是1.5以下的版本?

1

image 虽然可以订阅contextRefreshedEvent事件,但是如图所示,再1.5及以上版本这个config type为file,且是springboot下会关闭这个定时刷新配置,也就不会出现你上面的日志才对