lk_Session 2025-11-02 14:41 采纳率: 0%
浏览 8

偌依的微服务框架,nacos部署在服务器上,本地应用无法访问

我使用偌依的微服务框架,nacos部署在服务器上,并且在本地使用http://ip:8848/nacos%E8%83%BD%E8%AE%BF%E9%97%AE%E5%88%B0
现在我在本地启动ruoyi-gateway报错,ruoyi-gateway的server-addr: ip:8848 server-addr: ip:8848 都做了修改。
本地的nacos启动就可以访问,放到服务器上则不可以,nacos配置一直,使用的也是服务器上的一个数据库
报错如下:

14:26:59.190 [main] ERROR c.a.c.n.r.NacosServiceRegistry - [register,81] - nacos registry, ruoyi-gateway register failed...NacosRegistration{nacosDiscoveryProperties=NacosDiscoveryProperties{serverAddr='106.227.95.13:8848', username='', password='', endpoint='', namespace='', watchDelay=30000, logName='', service='ruoyi-gateway', weight=1.0, clusterName='', group='DEFAULT_GROUP', namingLoadCacheAtStart='false', metadata={IPv6=null, preserved.register.source=SPRING_CLOUD}, registerEnabled=true, ip='192.168.31.239', networkInterface='', port=8080, secure=false, accessKey='', secretKey='', heartBeatInterval=null, heartBeatTimeout=null, ipDeleteTimeout=null, instanceEnabled=true, ephemeral=true, failureToleranceEnabled=false}, ipDeleteTimeout=null, failFast=true}},
com.alibaba.nacos.api.exception.NacosException: Client not connected, current status:STARTING
    at com.alibaba.nacos.common.remote.client.RpcClient.request(RpcClient.java:639)
    at com.alibaba.nacos.common.remote.client.RpcClient.request(RpcClient.java:619)
    at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.requestToServer(NamingGrpcClientProxy.java:356)
    at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.doRegisterService(NamingGrpcClientProxy.java:209)
    at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.registerService(NamingGrpcClientProxy.java:123)
    at com.alibaba.nacos.client.naming.remote.NamingClientProxyDelegate.registerService(NamingClientProxyDelegate.java:98)
    at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:152)
    at com.alibaba.cloud.nacos.registry.NacosServiceRegistry.register(NacosServiceRegistry.java:75)
    at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.register(AbstractAutoServiceRegistration.java:232)
    at com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration.register(NacosAutoServiceRegistration.java:78)
    at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.start(AbstractAutoServiceRegistration.java:133)
    at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.bind(AbstractAutoServiceRegistration.java:98)
    at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:86)
    at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:47)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:178)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:171)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:145)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:430)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:387)
    at org.springframework.boot.web.reactive.context.WebServerManager.start(WebServerManager.java:57)
    at org.springframework.boot.web.reactive.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:40)
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:183)
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:58)
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:365)
    at java.base/java.lang.Iterable.forEach(Iterable.java:75)
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:160)
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:128)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:949)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:594)
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:409)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1289)
    at com.ruoyi.gateway.RuoYiGatewayApplication.main(RuoYiGatewayApplication.java:17)
14:26:59.190 [main] WARN  o.s.b.w.r.c.AnnotationConfigReactiveWebServerApplicationContext - [refresh,599] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is java.lang.reflect.UndeclaredThrowableException
14:27:01.625 [main] ERROR o.s.b.SpringApplication - [reportFailure,818] - Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is java.lang.reflect.UndeclaredThrowableException
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:186)
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:58)
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:365)
    at java.base/java.lang.Iterable.forEach(Iterable.java:75)
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:160)
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:128)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:949)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:594)
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:409)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1289)
    at com.ruoyi.gateway.RuoYiGatewayApplication.main(RuoYiGatewayApplication.java:17)
Caused by: java.lang.reflect.UndeclaredThrowableException: null
    at org.springframework.util.ReflectionUtils.rethrowRuntimeException(ReflectionUtils.java:147)
    at com.alibaba.cloud.nacos.registry.NacosServiceRegistry.register(NacosServiceRegistry.java:83)
    at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.register(AbstractAutoServiceRegistration.java:232)
    at com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration.register(NacosAutoServiceRegistration.java:78)
    at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.start(AbstractAutoServiceRegistration.java:133)
    at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.bind(AbstractAutoServiceRegistration.java:98)
    at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:86)
    at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:47)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:178)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:171)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:145)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:430)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:387)
    at org.springframework.boot.web.reactive.context.WebServerManager.start(WebServerManager.java:57)
    at org.springframework.boot.web.reactive.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:40)
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:183)
    ... 14 common frames omitted

  • 写回答

5条回答 默认 最新

  • 阿里嘎多学长 2025-11-02 14:54
    关注

    阿里嘎多学长整理AIGC生成,因移动端显示问题导致当前答案未能完全显示,请使用PC端查看更加详细的解答过程

    问题分析

    • 你使用的是偌依的微服务框架(可能是 Spring Cloud Alibaba 的 Ruoyi Framework)
    • Nacos 部署在服务器上
    • 本地应用无法访问 Nacos

    解决方案

    1. 检查 Nacos 服务是否启动: 确保 Nacos 服务已经启动,并且正在监听 8848 端口。
    2. 检查 Nacos 配置: 确保 Nacos 配置文件(可能是 application.propertiesapplication.yml) 中的 server 配置正确。
    3. 检查防火墙设置: 确保防火墙没有阻止本地应用访问 Nacos 服务。
    4. 检查 Nacos 服务注册: 确保本地应用已经成功注册到 Nacos 服务中。
    5. 尝试使用 Nacos 的负载均衡功能: 如果以上步骤都没有解决问题,可以尝试使用 Nacos 的负载均衡功能。

    核心代码

    # application.properties
    spring.cloud.nacos.server-addr=你的服务器IP:8848
    spring.cloud.nacos.username=你的用户名
    spring.cloud.nacos.password=你的密码
    
    // RuoyiApplication.java
    @SpringBootApplication
    public class RuoyiApplication {
        public static void main(String[] args) {
            SpringApplication.run(RuoyiApplication.class, args);
        }
    }
    
    // RuoyiConfig.java
    @Configuration
    public class RuoyiConfig {
        @Bean
        public NacosConfigProperties nacosConfigProperties() {
            NacosConfigProperties properties = new NacosConfigProperties();
            properties.setServerAddr("你的服务器IP:8848");
            properties.setUsername("你的用户名");
            properties.setPassword("你的密码");
            return properties;
        }
    }
    

    请注意,以上代码仅供参考,具体配置可能需要根据你的项目实际情况进行调整。

    评论

报告相同问题?

问题事件

  • 创建了问题 11月2日