当前位置: 首页 > 知识库问答 >
问题:

Spring API网关Java . net . connect异常:连接超时:没有进一步的信息

仇炜
2023-03-14

我有一个Spring启动应用程序,具有简单的GET方法“sayHello”,我已经配置了API网关,以便在uri模式匹配/ ms1 /**时路由对我的微服务模块的调用

网关和微服务都已注册到注册表服务,仪表板显示都已注册

API-GATEAY YAML配置

server:
  port: '8010'
spring:
  application:
    name: MY-GATEWAY
  cloud:
    compatibility-verifier:
      enabled: false
    gateway:
      routes:
        - id: MICRO-SERVICE1
          uri: lb://MICRO-SERVICE1
          predicates:
            - Path=/ms1/**
eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    service-uri: http://localhost:8761/eureka/
  intance:
    hostname: localhost

MICRO-SERVICE1 YAML配置

server:
  port: '8030'

spring:
  application:
    name: MICRO-SERVICE1
eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    service-uri: http://localhost:8761/eureka/
  intance:
    hostname: localhost

控制器的 GET 方法

@RestController
@RequestMapping("/ms1")
public class UATController {
    @GetMapping(value = "/sayHello")
    public @ResponseBody ResponseEntity<String> sayHello() {
        String message = "Hello World";
        return new ResponseEntity<String>(message, HttpStatus.OK);
    }
}

当我通过网关访问时,我遇到了以下错误,但是当我直接访问我的微服务时,它能正常工作吗?

  • http://localhost:8010/ms1/sayHello
Wed Dec 07 23:32:31 EST 2021
[83b324d4-2] There was an unexpected error (type=Internal Server Error, status=500).
Connection timed out: no further information: DESKTOP-1.verizon.net/192.168.1.160:8030
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: DESKTOP-1.verizon.net/192.168.1.160:8030
    Suppressed: The stacktrace has been enhanced by Reactor, refer to additional information below: 
Error has been observed at the following site(s):
    *__checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
    *__checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
    *__checkpoint ⇢ HTTP GET "/ms1/sayHello" [ExceptionHandlingWebHandler]
Original Stack Trace:
Caused by: java.net.ConnectException: Connection timed out: no further information
    at java.base/sun.nio.ch.Net.pollConnect(Native Method)
    at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
    at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:946)
    at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:330)
    at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:707)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:833)

共有3个答案

阳航
2023-03-14

已经在yml文件中为我添加了所有服务及其工作的设置。

尤里卡:实例:首选ip地址:真

宇文和昶
2023-03-14

将DESKTOP-1.verizon.net添加到hosts文件成功了,下面是我添加到C:\ Windows \ System32 \ drivers \ etc \ hosts文件中的条目。不幸的是,eureka . instance . prefer-IP-address = true对我不起作用

127.0.0.1   DESKTOP-1.verizon.net
漆雕和雅
2023-03-14

今天,我在本地主机上运行微服务、网关和Eureka发现时也遇到了同样的问题。

我可以通过将< code > eureka . instance . preferip address = true 添加到我的应用程序来解决这个问题。该属性导致服务将通告它们的IP地址而不是主机名。第2.6点下有更多信息:https://cloud . spring . io/spring-cloud-网飞/multi/multi _ spring-cloud-eureka-server . html。我的猜测是,由于使用localhost,将请求转发到微服务时出现了问题。

编辑:这是我的设置。我的设置没有什么特别的。这些是我在application.properties微服务中使用的值:

spring.cloud.discovery.enabled=true
spring.application.name=[The name of my app]
eureka.client.register.with-eureka=true
eureka.client.service-url.defaultZone=http://localhost:8999/eureka
eureka.instance.prefer-ip-address=true

网关的属性类似于服务属性。负载平衡部分如下所示:

spring.cloud.gateway.routes[0].id=[Same name as my app]
spring.cloud.gateway.routes[0].uri=lb://[name of my app]
spring.cloud.gateway.routes[0].predicates=Path=/test/**

其中测试/** 是我的应用程序的其余 URL 的一部分

 类似资料:
  • 我修改了此处可用于客户端和服务器My Client的示例代码: 我通过创建多个线程在同一台机器上创建多个客户端。线程的数量由n的值决定。当我运行少量客户端时,我不会遇到任何问题,但当我使用n运行500个(即500个客户端线程)时,一些线程会正确运行,但在一些线程中,我会遇到以下情况: 第143行是:所以当我读到这个方法的留档时,它说它抛出: NoConnectionPendingException

  • 代码片段如下所示: 如果有人有决议,请帮忙?

  • 一些背景: 我有一个使用3G或4G数据连接的Android应用程序。但它也连接到一个wifi热点,以便在热点设备和应用程序之间传输一些数据。 我想做的是:创建一个到这个wifi热点的套接字连接,并通过这个套接字发送/接收数据。 我添加了以下代码,以确保我们在创建套接字时使用wifi热点wifi(否则它有时最终会使用数据连接): 这似乎没问题。但是,我在尝试连接到远程服务器地址时发现问题。下面是我正

  • 我在eclipse IDE中使用Spring Mail尝试发送电子邮件,但控制台总是打印“连接超时”异常。我已经确认可以通过telnet连接到邮件服务器。我对Spring MVC框架相当陌生。可能是因为我没有配置spring mvc。xml对吗?不过,我没有在代码中使用依赖项注入。以下是代码和例外情况。感谢您的宝贵意见。 在控制台中打印的异常: 消息请求处理失败;嵌套的异常是org。springf

  • 我相对来说是android开发的新手。我正在开发一个android应用程序,向web服务器发送请求并解析JSON对象。在与服务器通信时,我经常收到< code > Java . net . socket time out exception:Connection timed out 异常。有时它会完美地工作,没有任何问题。我知道这个问题已经被问过很多次了。但仍然,我没有得到任何满意的解决这个问题的

  • 问题是,我想写一个Java程序来增加特定URL的页面点击量。目前我只是在网上冲浪,并得到一些基本的程序来做测试。然而,我甚至无法使程序运行...下面是我的程序和相关输出。 Eclipse、Java程序: 以下是输出: 线程“main”java.net.ConnectException:连接超时:java.net.plainsockeTimpl.SocketConnect(本机方法)java.net