记一次nacos启动异常-版本为题导致after all servers
本地环境
nacos-client: 0.6.2
spring-cloud-starter-alibaba-nacos-config:0.2.1.RELEASE
spring-cloud-starter-alibaba-nacos-discovery:0.2.1.RELEASE
异常描述
启动拉取nacos配置正常,但是未注册到nacos服务列表,异常如下:
2022-01-05 15:27:45,203 [main] ERROR [org.springframework.cloud.alibaba.nacos.registry.NacosServiceRegistry] [NacosServiceRegistry.java:61] [trace=,span=,parent=] - nacos registry, **-***-adviser register failed...NacosRegistration{nacosDiscoveryProperties=NacosDiscoveryProperties{serverAddr='127.0.0.1:80', endpoint='', namespace='e3661729-85f8-46c5-b03a-80f6f328d4c4', logName='', service='**-***-adviser', weight=1.0, clusterName='DEFAULT', metadata={}, registerEnabled=true, ip='10.2.5.140', networkInterface='', port=8080, secure=false, accessKey=', namingLoadCacheAtStart=false', secretKey=''}},
java.lang.IllegalStateException: failed to req API:/nacos/v1/ns/instance after all servers([127.0.0.1:80]) tried
at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:335)
at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:267)
at com.alibaba.nacos.client.naming.net.NamingProxy.registerService(NamingProxy.java:167)
at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:170)
at org.springframework.cloud.alibaba.nacos.registry.NacosServiceRegistry.register(NacosServiceRegistry.java:56)
at org.springframework.cloud.alibaba.nacos.registry.NacosServiceRegistry.register(NacosServiceRegistry.java:29)
at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.register(AbstractAutoServiceRegistration.java:209)
at org.springframework.cloud.alibaba.nacos.registry.NacosAutoServiceRegistration.register(NacosAutoServiceRegistration.java:75)
at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.start(AbstractAutoServiceRegistration.java:108)
at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.bind(AbstractAutoServiceRegistration.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:261)
at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:180)
at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:142)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:400)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:354)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:164)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)
at com.bbj.adviser.AdviserApplication.main(AdviserApplication.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
问题分析:
通过分析错误发现是服务注册的时候出现的异常,所以在NacosServiceRegistry:56行断点跟踪

进入NamingProxy.reqAPI

在callServer函数会出现真正的异常信息:

从这里基本可以推断服务端找不到对应的service导致的,一般是版本问题太高或者太低导致的。
解决:
将nacos版本升级即可
nacos-client:1.0.0
spring-cloud-starter-alibaba-nacos-config:0.2.2.RELEASE
spring-cloud-starter-alibaba-nacos-discovery:0.2.2.RELEASE

浙公网安备 33010602011771号