服务下线时抛出异常:
[SpringContextShutdownHook] ERROR c.a.cloud.nacos.discovery.NacosWatch 180 -> namingService unsubscribe failed, properties:NacosDiscoveryProperties{serverAddr='project-pattern:10001', username='', password='', endpoint='', namespace='syz', watchDelay=30000, logName='', service='work-file-simon', weight=1.0, clusterName='DEFAULT', group='DEFAULT_GROUP', namingLoadCacheAtStart='false', metadata={preserved.register.source=SPRING_CLOUD}, registerEnabled=true, ip='192.168.0.196', networkInterface='', port=13132, secure=false, accessKey='', secretKey='', heartBeatInterval=null, heartBeatTimeout=null, ipDeleteTimeout=null, instanceEnabled=true, ephemeral=true, failureToleranceEnabled=false}, ipDeleteTimeout=null, failFast=true}
java.lang.IllegalStateException: UT015023: This Context has been already destroyed
at io.undertow.servlet.spec.ServletContextImpl.getDeploymentInfo(ServletContextImpl.java:211)
at io.undertow.servlet.spec.ServletContextImpl.getInitParameterNames(ServletContextImpl.java:449)
at org.springframework.web.context.support.ServletContextPropertySource.getPropertyNames(ServletContextPropertySource.java:41)
at com.alibaba.spring.util.PropertySourcesUtils.getPropertyNames(PropertySourcesUtils.java:130)
at com.alibaba.spring.util.PropertySourcesUtils.getSubProperties(PropertySourcesUtils.java:103)
at com.alibaba.spring.util.PropertySourcesUtils.getSubProperties(PropertySourcesUtils.java:57)
at com.alibaba.cloud.nacos.NacosDiscoveryProperties.enrichNacosDiscoveryProperties(NacosDiscoveryProperties.java:657)
at com.alibaba.cloud.nacos.NacosDiscoveryProperties.getNacosProperties(NacosDiscoveryProperties.java:651)
at com.alibaba.cloud.nacos.discovery.NacosWatch.stop(NacosWatch.java:175)
at com.alibaba.cloud.nacos.discovery.NacosWatch.stop(NacosWatch.java:107)
at org.springframework.context.support.DefaultLifecycleProcessor.doStop(DefaultLifecycleProcessor.java:234)
at org.springframework.context.support.DefaultLifecycleProcessor.access$300(DefaultLifecycleProcessor.java:54)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.stop(DefaultLifecycleProcessor.java:373)
at org.springframework.context.support.DefaultLifecycleProcessor.stopBeans(DefaultLifecycleProcessor.java:206)
at org.springframework.context.support.DefaultLifecycleProcessor.onClose(DefaultLifecycleProcessor.java:129)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1067)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.doClose(ServletWebServerApplicationContext.java:172)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:991)
出现错误原因:
由于服务下线时触发关闭Hook,undertow在nacos之前先关闭了,导致naocs取不到undertow里面的对象,导致空指针异常
处理方式:
1、这里导致服务无法下线,故可以重写这个 naocs 的 Hook
2、调整NacosWatch关闭顺序,在springcloudalibaba 2.2.8.RELEASE 已修复这个问题
3、放任这个错误,添加一个补充nacos服务下线
例:监听 spring的ContextClosedEvent ,在方法里面调用NacosAutoServiceRegistration 的destroy()方法
文章来源:https://www.toymoban.com/news/detail-508798.html
例:在服务里添加一个接口 调用NacosAutoServiceRegistration.stop()。在下线的方法或者是脚本里面调用这个接口(需在实际关闭之前调用)文章来源地址https://www.toymoban.com/news/detail-508798.html
到了这里,关于SpringCloud使用nacos注册微服务,undertow为web服务器时,微服务下线问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!