简体   繁体   English

路由到网关的问题微服务

[英]Issue Microservice routed to Gateway

I've built seperately:我单独建造:

Eureka Server, Spring Cloud Gateway (+ Discovery Client), Spring Web App (+ Discovery Client) Eureka Server,Spring Cloud Gateway(+ Discovery Client),Spring Web App(+ Discovery Client)

Eureka Server Main Class : Eureka Server Main Class

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class ServiceRegistryApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServiceRegistryApplication.class, args);
    }

}

and application.ymlapplication.yml

server:
   port: 8761
   
eureka:
   client:
      fetch-registry: false
      register-with-eureka: false

Gateway Main Class : Gateway Main Class :

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@SpringBootApplication
@EnableEurekaClient
public class GatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class, args);
    }

}

and application.ymlapplication.yml

server:
   port: 8080
   
spring:
   application:
      name: GATEWAY
   cloud:
      gateway:
         routes:
            -id: MICROSERVICE
            uri: lb://MICROSERVICE
            predicates:
                - Path: /service/**

         
eureka:
   client:
      register-with-eureka: true
      fetch-registry: true
      service-url: 
         defualtZone: http://localhost:8761/eureka
   instance: localhost

Microservice Main Class : Microservice Main Class

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@SpringBootApplication
@EnableEurekaClient
public class MicroserviceApplication {

    public static void main(String[] args) {
        SpringApplication.run(MicroserviceApplication.class, args);
    }

}

Microservice Controller : Microservice Controller

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping
@RestController
public class HelloController {

    @GetMapping("/test")
    public String getWelcomed() {
        return "Welcome to Microservice !";
    }
}

and application.ymlapplication.yml

server:
   port: 8099

spring:
   application:
      name: MICROSERVICE
   
eureka:
   client:
      register-with-eureka: true
      fetch-registry: true
      service-url: 
         defualtZone: http://localhost:8761/eureka
   instance: localhost

My issue now is that I can't access my microservice '/test' call through the gateway.我现在的问题是我无法通过网关访问我的微服务“/test”调用。 I keep getting this error:我不断收到此错误:

Whitelabel Error Page This application has no configured error view, so you are seeing this as a fallback. Whitelabel Error Page 此应用程序没有配置错误视图,因此您将其视为后备。

Wed Dec 23 21:10:14 WEST 2020 [3c6a9e3d-9] There was an unexpected error (type=Not Found, status=404). 2020 年 12 月 23 日星期三 21:10:14 WEST [3c6a9e3d-9] 出现意外错误(类型 = 未找到,状态 = 404)。 org.springframework.web.server.ResponseStatusException: 404 NOT_FOUND at org.springframework.web.reactive.resource.ResourceWebHandler.lambda$handle$0(ResourceWebHandler.java:325) Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 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 "/service/test" [ExceptionHandlingWebHandler] Stack trace: at org.springframework.web.reactive.resource.ResourceWebHandler.lambda$handle$0(ResourceWebHandler.java:325) at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:44) at reactor.core.publisher.Mono.subscribe(Mono.java:4252) at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubs org.springframework.web.server.ResponseStatusException: 404 NOT_FOUND at org.springframework.web.reactive.resource.ResourceWebHandler.lambda$handle$0(ResourceWebHandler.java:325) 抑制:reactor.core.publisher$OnAssemblyException$OnAssemblyOnAssembly在以下站点被观察到:|_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain] |_ checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [ DefaultWebFilterChain] |_ checkpoint ⇢ HTTP GET "/service/test" [ExceptionHandlingWebHandler] 堆栈跟踪:在 org.springframework.web.reactive.resource.ResourceWebHandler.lambda$handle$0(ResourceWebHandler.java:corepuber) 在 reactor.corepublisher .MonoDefer.subscribe(MonoDefer.java:44) 在 reactor.core.publisher.Mono.subscribe(Mono.java:4252) 在 reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubs criber.onComplete(FluxSwitchIfEmpty.java:75) at reactor.core.publisher.MonoFlatMap$FlatMapMain.onComplete(MonoFlatMap.java:174) at reactor.core.publisher.MonoNext$NextSubscriber.onComplete(MonoNext.java:96) at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.drain(FluxConcatMap.java:359) at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.onSubscribe(FluxConcatMap.java:211) at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:161) at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:86) at reactor.core.publisher.Mono.subscribe(Mono.java:4252) at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain(MonoIgnoreThen.java:172) at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:56) at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:150) at reactor.core.publisher.FluxSwitchIfEmpty$Switc criber.onComplete(FluxSwitchIfEmpty.java:75) 在 reactor.core.publisher.MonoFlatMap$FlatMapMain.onComplete(MonoFlatMap.java:174) 在 reactor.core.publisher.MonoNext$NextSubscriber.onComplete(MonoNext.882158284:6946) 在 reactor .core.publisher.FluxConcatMap$ConcatMapImmediate.drain(FluxConcatMap.java:359) 在 reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.onSubscribe(FluxConcatMap.java:211) 在 reactor.core.publisher.FluxIterable.subscribe(8246138.subscribe8246138.8 :161) 在 reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:86) 在 reactor.core.publisher.Mono.subscribe(Mono.java:4252) 在 reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain( MonoIgnoreThen.java:172)在reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:56)在reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:150)在reactor.core.core.publisherIfpublisherFluxerFlux。 $开关hIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:67) at reactor.core.publisher.MonoNext$NextSubscriber.onNext(MonoNext.java:76) at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.innerNext(FluxConcatMap.java:274) at reactor.core.publisher.FluxConcatMap$ConcatMapInner.onNext(FluxConcatMap.java:851) at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:121) at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2344) at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:162) at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.set(Operators.java:2152) at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onSubscribe(Operators.java:2026) at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onSubscribe(FluxMapFuseable.java:90) at reactor.core.publisher.M hIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:67) 在 reactor.core.publisher.MonoNext$NextSubscriber.onNext(MonoNext.java:76) 在 reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.innerNext(FluxConcatMap2446945888:76) 在 reactor: .core.publisher.FluxConcatMap$ConcatMapInner.onNext(FluxConcatMap.java:851) 在 reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:121) 在 reactor.core.publisher.Operators$ScalarSubscription.request(Operators) .java:2344) 在 reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:162) 在 reactor.core.publisher.Operators$MultiSubscriptionSubscriber.set(Operators.java:2152) 在 reactor.publisher.publisher.运营商 $MultiSubscriptionSubscriber.onSubscribe(Operators.java:2026) 在 reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onSubscribe(FluxMapFuseable.java:90) 在 reactor.core.publisher.M onoJust.subscribe(MonoJust.java:54) at reactor.core.publisher.Mono.subscribe(Mono.java:4252) at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.drain(FluxConcatMap.java:441) at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.onSubscribe(FluxConcatMap.java:211) at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:161) at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:86) at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java onoJust.subscribe(MonoJust.java:54) 在 reactor.core.publisher.Mono.subscribe(Mono.java:4252) 在 reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.drain(FluxConcatMap.java:4252) 在 reactor.44 .publisher.FluxConcatMap$ConcatMapImmediate.onSubscribe(FluxConcatMap.java:211) 在 reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:161) 在 reactor.core.publisher.FluxIterable.subscribe(FluxIterable.8821382846845) 在reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)在reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)在reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)在 reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) :52) at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) at reactor.core.publisher.Mono.subscribe(Mono.java:4252) at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain(MonoIgnoreThen.java:172) at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:56) at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) at reactor.netty.http.server.HttpServerHandle.onStateChange(HttpServerHandle.java:65) at reactor.netty.ReactorNetty$CompositeConnectionObserver.onStateChange(ReactorNetty.java:518) at reactor.netty.tcp.TcpServerBind$ChildObserver.onStateChange(TcpServerBind.java:278) at reactor.netty.http.server.HttpServerOperations.onInboundNext(HttpServerOperations.java:475) at reactor.netty.channel.ChannelOp :52) 在 reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) 在 reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) 在 reactor.core.publisher.Mono.subscribe(Mono. java:4252) 在 reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain(MonoIgnoreThen.java:172) 在 reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:56) 在 reactor.MonsubscribererIntercore.MonopublisherIntercore. (InternalMonoOperator.java:64) at reactor.netty.http.server.HttpServerHandle.onStateChange(HttpServerHandle.java:65) at reactor.netty.ReactorNetty$CompositeConnectionObserver.onStateChange(ReactorNetty.java:518) at reactor.netty.tcp. TcpServerBind$ChildObserver.onStateChange(TcpServerBind.java:278) 在 reactor.netty.http.server.HttpServerOperations.onInboundNext(HttpServerOperations.java:475) 在 reactor.netty.channel.ChannelOp erationsHandler.channelRead(ChannelOperationsHandler.java:96) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at reactor.netty.http.server.HttpTrafficHandler.channelRead(HttpTrafficHandler.java:191) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDup erationsHandler.channelRead(ChannelOperationsHandler.java:96) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel .AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at reactor.netty.http.server.HttpTrafficHandler.channelRead(HttpTrafficHandler.java:191) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io. netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDup lexHandler.java:436) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296) at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(Abstra lexHandler.java:436) 在 io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324) 在 io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.882132848:94588:94658) .CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty. channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io .netty.channel.AbstractChannelHandlerContext.invokeChannelRead(Abstra ctChannelHandlerContext.java:365) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719) 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:989) 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:834) ctChannelHandlerContext.java:365) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) at io.netty.channel .nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719) 在 io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655) 在 io.netty.channel.nio.NioEventLoop.processSelected5Loop.84:862413Loop28 ) 在 io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) 在 io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) 在 io.netty.util.internal.ThreadExecutorMap $2.run(ThreadExecutorMap.java:74) 在 io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) 在 java.base/java.lang.Thread.run(Thread.8984538286)

I've tried hiding the gateway from my eureka server based on some suggestions I've found, yet the issue persists by addind this to my application.yml in gateway:我已经尝试根据我发现的一些建议从我的尤里卡服务器隐藏网关,但是通过将其添加到网关中的application.yml中问题仍然存在:

eureka:
   client:
      register-with-eureka: false
      fetch-registry: false

controller should be controller应该是

@RestController
@RequestMapping("/service")
public class HelloController

and the URL: http://localhost:8080/service/test和 URL:http://localhost:8080/service/test

or you can leave @RequestMapping() in the controller and make the gateway using this path:或者您可以将@RequestMapping()留在 controller 中,并使用此路径创建网关:

predicates:
 -Path=/**

then the URL should be: http://localhost:8080/test那么 URL 应该是:http://localhost:8080/test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法通过网关访问微服务 - Cannot access the microservice through the gateway 在没有数据库的 JHipster 微服务架构中创建网关 - Creating a Gateway in JHipster microservice arhitecture without database 通过网关从 JHipster UAA 微服务获取错误详细信息 - Getting error details from JHipster UAA microservice through gateway Zuul Gateway 服务无法转发到 Eureka 服务器注册的微服务 - Zuul Gateway service unable to forward to microservice registered with Eureka server 微服务通过 Zuul 网关返回 405 - Microservice returning 405 after going through Zuul gateway 如何从JHIPSTER网关存储库或服务手动调用微服务 - How to manually call a microservice from a JHIPSTER gateway repository or service 使用 Spring Boot 从另一个微服务访问网关属性 - Accessing Gateway Properties from another microservice using Spring boot Spring 在 Google Cloud 上启动微服务部署问题 - Spring Boot Microservice Deployment issue on Google Cloud Drools规则与Jhipster微服务奇怪的问题 - Drools rule with jhipster microservice strange issue 在微服务架构中,我有包含用户详细信息的微服务,但在 zuul API 网关中,我想对我的请求进行身份验证 - In microservice archticture, i have microservice which have user detail but in zuul API gateway i want to authenticate my requests
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM