我正在使用
java 21
和 spring boot 3.3.0(RC1)
。
我已经制作了 1 个微服务用户微服务。它的 application.yaml 文件看起来像这样
server:
port: 5001
spring:
application:
name: USER-SERVICE
datasource:
url: #
username: #
password: #
jpa:
hibernate:
ddl-auto: update
eureka:
instance:
prefer-ip-address: true
client:
fetch-registry: true
register-with-eureka: true
serviceUrl:
defaultZone: http://localhost:8081/eureka/
我已经制作了尤里卡服务器,并且上述微服务也注册到该服务器。 该服务器的 application.yaml 是:
server:
port: 8081
eureka:
instance:
hostname: localhost
client:
register-with-eureka: false
fetch-registry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
现在我所做的是使用
reactive gateway
依赖项创建了一个云网关,从这里路由所有微服务端点。
application.yaml 文件是:
spring:
application:
name: GATEWAY-SERVICE
cloud:
gateway:
routes: #setup paths here
- id: USER-SERVICE
uri: lb://USER-SERVICE
predicates:
- Path=/auth/**, /api/user/**
default-filters: #setup cors here
- DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
globalcors: #setup cors here
cors-configurations:
'[/**]':
allowedOrigins: "*"
allowedMethods: "*"
allowedHeaders: "*"
server:
port: 6500
eureka:
instance:
prefer-ip-address: true
client:
fetch-registry: true
register-with-eureka: true
serviceUrl:
defaultZone: http://localhost:8081/eureka/
并且该网关也注册到了 eureka 服务器。现在当我去
http://localhost:8081
我可以看到 2 个微服务,一个用于
user service
,另一个用于 gateway
,即将出现,它们是 UP
。
他们的状态看起来像这样
192.168.1.4:USER-SERVICE:5001
192.168.1.4:GATEWAY-SERVICE:6500
现在,当我从邮递员那里点击
http://localhost:6500/auth/login
时,我收到 500 错误,用户服务控制台中没有错误,但网关服务中有错误。
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: /192.168.1.4:5001
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
*__checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
*__checkpoint ⇢ HTTP POST "/auth/login" [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) ~[na:na]
at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:682) ~[na:na]
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:973) ~[na:na]
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:337) ~[netty-transport-4.1.109.Final.jar:4.1.109.Final]
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:339) ~[netty-transport-4.1.109.Final.jar:4.1.109.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776) ~[netty-transport-4.1.109.Final.jar:4.1.109.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[netty-transport-4.1.109.Final.jar:4.1.109.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[netty-transport-4.1.109.Final.jar:4.1.109.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[netty-transport-4.1.109.Final.jar:4.1.109.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.109.Final.jar:4.1.109.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.109.Final.jar:4.1.109.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.109.Final.jar:4.1.109.Final]
at java.base/java.lang.Thread.run(Thread.java:1583) ~[na:na]
当我在邮递员中点击
http://localhost:5001/auth/login
时,我得到了正确的回复。
还有一件事,这个完整的设置正在我的本地计算机上运行。 我无法弄清楚这一点。需要帮助。如果您需要任何其他代码,我可以添加它。
没关系。我的脑残防病毒防火墙不允许任何连接。因此,如果您收到此错误,请禁用防病毒软件的防火墙,然后重试。它会起作用的。