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

8fsztsew  于 22天前  发布在  Spring
关注(0)|答案(6)|浏览(14)

当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

有优化或者版本升级吗?

z4bn682m

z4bn682m1#

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

mlnl4t2r

mlnl4t2r2#

是的 就是因为单例的原因

w8f9ii69

w8f9ii693#

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

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

edqdpe6u

edqdpe6u4#

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

uyhoqukh

uyhoqukh5#

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

vof42yt1

vof42yt16#

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

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

相关问题