微服务工程,nacos启动之后,启动项目的网关,报错

16:09:22.005 [main] WARN  c.a.n.c.c.NacosConfigService - [getConfigInner,173] - [config_rpc_client] [get-config] get from server error, dataId=sentinel-ruoyi-gateway, group=DEFAULT_GROUP, tenant=, msg=ErrCode:-401, ErrMsg:Client not connected,current status:STARTING
16:09:22.006 [main] WARN  c.a.n.c.c.NacosConfigService - [getConfigInner,177] - [config_rpc_client] [get-config] get snapshot ok, dataId=sentinel-ruoyi-gateway, group=DEFAULT_GROUP, tenant=, config=
16:09:22.007 [main] WARN  c.a.c.s.d.c.SentinelConverter - [convert,80] - converter can not convert rules because source is empty
16:09:22.010 [com.alibaba.nacos.client.Worker] ERROR c.a.n.c.r.client - [printIfErrorEnabled,99] - Send request fail, request=ConfigBatchListenRequest{headers={Client-AppName=unknown, Client-RequestTS=1623139761703, charset=UTF-8, Client-RequestToken=63fd2ac4c942e75574ad5ec033036167, exConfigInfo=true, Timestamp=1623139761703}, requestId='null'}, retryTimes=2,errorMessage=Client not connected,current status:STARTING
16:09:22.018 [com.alibaba.nacos.client.Worker] ERROR c.a.n.c.c.i.ClientWorker - [executeConfigListen,797] - Async listen config change error
com.alibaba.nacos.api.exception.NacosException: Client not connected,current status:STARTING
    at com.alibaba.nacos.common.remote.client.RpcClient.request(RpcClient.java:628)
    at com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient.requestProxy(ClientWorker.java:976)
    at com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient.requestProxy(ClientWorker.java:951)
    at com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient.executeConfigListen(ClientWorker.java:757)
    at com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient$3.run(ClientWorker.java:677)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
16:09:22.277 [main] INFO  c.a.n.c.i.CredentialWatcher - [loadCredential,165] - null No credential found
16:09:22.380 [main] ERROR c.a.n.c.r.client - [printIfErrorEnabled,99] - Send request fail, request=SubscribeServiceRequest{headers={app=unknown}, requestId='null'}, retryTimes=0,errorMessage=Client not connected,current status:STARTING
16:09:22.481 [main] ERROR c.a.n.c.r.client - [printIfErrorEnabled,99] - Send request fail, request=SubscribeServiceRequest{headers={app=unknown}, requestId='null'}, retryTimes=1,errorMessage=Client not connected,current status:STARTING
16:09:22.582 [main] ERROR c.a.n.c.r.client - [printIfErrorEnabled,99] - Send request fail, request=SubscribeServiceRequest{headers={app=unknown}, requestId='null'}, retryTimes=2,errorMessage=Client not connected,current status:STARTING
16:09:22.582 [main] ERROR c.a.c.n.d.NacosWatch - [start,127] - namingService subscribe failed, properties:NacosDiscoveryProperties{serverAddr='localhost:8848', endpoint='', namespace='', watchDelay=30000, logName='', service='ruoyi-gateway', weight=1.0, clusterName='DEFAULT', group='DEFAULT_GROUP', namingLoadCacheAtStart='false', metadata={preserved.register.source=SPRING_CLOUD}, registerEnabled=true, ip='192.168.43.60', networkInterface='', port=-1, secure=false, accessKey='', secretKey='', heartBeatInterval=null, heartBeatTimeout=null, ipDeleteTimeout=null}
com.alibaba.nacos.api.exception.NacosException: Request nacos server failed:
    at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.requestToServer(NamingGrpcClientProxy.java:213)
    at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.subscribe(NamingGrpcClientProxy.java:172)
    at com.alibaba.nacos.client.naming.remote.NamingClientProxyDelegate.subscribe(NamingClientProxyDelegate.java:146)
    at com.alibaba.nacos.client.naming.NacosNamingService.subscribe(NacosNamingService.java:387)
    at com.alibaba.cloud.nacos.discovery.NacosWatch.start(NacosWatch.java:123)
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54)
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)
    at java.lang.Iterable.forEach(Iterable.java:75)
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155)
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586)
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:64)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:438)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:337)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1336)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1325)
    at com.ruoyi.gateway.RuoYiGatewayApplication.main(RuoYiGatewayApplication.java:17)

 

gateway配置如下

# Tomcat
server:
  port: 8099

# Spring
spring: 
  application:
    # 应用名称
    name: ruoyi-gateway
  profiles:
    # 环境配置
    active: dev
  main:
    allow-bean-definition-overriding: true
  cloud:
    nacos:
      discovery:
        # 服务注册地址
        server-addr: localhost:8848
      config:
        # 配置中心地址
        server-addr: localhost:8848
        # 配置文件格式
        file-extension: yml
        # 共享配置
        shared-configs:
          -application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
    sentinel:
      # 取消控制台懒加载
      eager: true
      transport:
        # 控制台地址
        dashboard: 127.0.0.1:8718
      # nacos配置持久化
      datasource:
        ds1:
          nacos:
            server-addr: 127.0.0.1:8848
            dataId: sentinel-ruoyi-gateway
            groupId: DEFAULT_GROUP
            data-type: json
            rule-type: flow

 

nacos中网关的配置如下:

spring:

redis:

host: localhost

port: 6379

password:

cloud:

gateway:

discovery:

locator:

lowerCaseServiceId: true

enabled: true

routes:

# 认证中心

- id: ruoyi-auth

uri: lb://ruoyi-auth

predicates:

- Path=/auth/**

filters:

# 验证码处理

- CacheRequestFilter

- ValidateCodeFilter

- StripPrefix=1

# 代码生成

- id: ruoyi-gen

uri: lb://ruoyi-gen

predicates:

- Path=/code/**

filters:

- StripPrefix=1

# 定时任务

- id: ruoyi-job

uri: lb://ruoyi-job

predicates:

- Path=/schedule/**

filters:

- StripPrefix=1

# 系统模块

- id: ruoyi-system

uri: lb://ruoyi-system

predicates:

- Path=/system/**

filters:

- StripPrefix=1

# 文件服务

- id: ruoyi-file

uri: lb://ruoyi-file

predicates:

- Path=/file/**

filters:

- StripPrefix=1

 

# 不校验白名单

ignore:

whites:

- /auth/logout

- /auth/login

- /*/v2/api-docs

- /csrf

 

本地的nacos启动了,可以正常访问控制台,但是程序访问报错:namingService subscribe failed,有没有大佬呀

连接nacos服务异常了。Request nacos server failed:

nacos没有连接上,你看看你的nacos确定启动没(看能不能进到web控制台中),

还有一种情况就是boot 、 cloud、 nacos等相关的版本不匹配

同问,请问楼主你现在解决了吗,我这里跟你一样的问题

docker的话需要再映射-p 9848:9848 这个端口

我们也遇到了这个问题,nacos已成功启动,前端可登陆,但启动 ruoyi-modules-system.jar时,程序报错:
14:56:09.377 [main] INFO c.a.n.c.r.client - [printIfInfoEnabled,60] - [64a74013-051b-48ef-92d5-591f26bca290_config-0]RpcClient init, ServerListFactory =com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient$2
14:56:09.385 [main] INFO c.a.n.c.r.client - [printIfInfoEnabled,60] - [64a74013-051b-48ef-92d5-591f26bca290_config-0] Try to connect to server on start up, server: {serverIp='127.0.0.1', server main port=8848}
14:56:12.737 [main] ERROR c.a.n.c.r.c.g.GrpcClient - [printIfErrorEnabled,99] - Server check fail, please check server 127.0.0.1 ,port 9848 is available , error ={}
java.util.concurrent.TimeoutException: Waited 3000 milliseconds (plus 375631 nanoseconds delay) for com.alibaba.nacos.shaded.io.grpc.stub.ClientCalls$GrpcFuture@17776a8
[status=PENDING, info=[GrpcFuture{clientCall={delegate={delegate=ClientCallImpl{method=MethodDescriptor{fullMethodName=Request/request, type=UNARY, idempotent=false, safe=false, sampledToLocalTracing=true, requestMarshaller=com.alibaba.nacos.shaded.io.grpc.protobuf.lite.ProtoLiteUtils$MessageMarshaller@69a10787, responseMarshaller=com.alibaba.nacos.shaded.io.grpc.protobuf.lite.ProtoLiteUtils$MessageMarshaller@2d127a61, schemaDescriptor=com.alibaba.nacos.api.grpc.auto.RequestGrpc$RequestMethodDescriptorSupplier@2bbaf4f0}}}}}]]
at com.alibaba.nacos.shaded.com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:508)
at com.alibaba.nacos.common.remote.client.grpc.GrpcClient.serverCheck(GrpcClient.java:146)
at com.alibaba.nacos.common.remote.client.grpc.GrpcClient.connectToServer(GrpcClient.java:268)
at com.alibaba.nacos.common.remote.client.RpcClient.start(RpcClient.java:394)
at com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient.ensureRpcClient(ClientWorker.java:941)
at com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient.getOneRunningClient(ClientWorker.java:1104)
at com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient.queryConfig(ClientWorker.java:996)
at com.alibaba.nacos.client.config.impl.ClientWorker.getServerConfig(ClientWorker.java:407)
at com.alibaba.nacos.client.config.NacosConfigService.getConfigInner(NacosConfigService.java:166)
at com.alibaba.nacos.client.config.NacosConfigService.getConfig(NacosConfigService.java:94)
at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.loadNacosData(NacosPropertySourceBuilder.java:85)
at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.build(NacosPropertySourceBuilder.java:73)
at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosPropertySource(NacosPropertySourceLocator.java:199)
at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosDataIfPresent(NacosPropertySourceLocator.java:186)
at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosConfiguration(NacosPropertySourceLocator.java:158)
at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadSharedConfiguration(NacosPropertySourceLocator.java:116)
at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.locate(NacosPropertySourceLocator.java:101)
at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:51)
at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:47)
at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:95)
at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:610)
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:378)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:301)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290)
at com.ruoyi.system.RuoYiSystemApplication.main(RuoYiSystemApplication.java:22)
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:498)
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)

这个是因为nacos-client 2.0之后加了rpc,你可以降到1.4几,或者像楼上说的把整个版本从2.2.7将到2.2.5 ,2.2.5默认nacos-client是1.4.1

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632