繁体   English   中英

Spring Boot Zuul API Gateway 返回 404 响应

[英]Spring Boot Zuul API Gateway returning a 404 response

我正在尝试设置 Spring Boot Zuul 2.2,以便我可以向注册到 Eureka 并因此为 Zuul 所知的服务发送请求。

我可以通过 Zuul 访问服务的 Swagger UI,但是当我尝试向服务发送请求时,我收到404 HTTP status - not found响应。

服务配置如下:

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: always
eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://localhost:8761/eureka
  instance:
    preferIpAddress: true

Zuul 应用程序配置如下:

eureka:
  instance:
    preferIpAddress: true
  client:
    registerWithEureka: true
    fetchRegistry: true
spring:
  application:
    name: app-zuul
management:
  endpoints:
    web:
      exposure:
        include: routes,filters
  endpoint:
    health:
      show-details: always

最后,尤里卡配置:

eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false
spring:
  application:
    name: app-eureka
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: always

我可以通过http://localhost:3335/api/v1/...直接向用户服务发送请求,但是当我尝试请求http://localhost:8763/app-user/api/v1/...时收到404 http://localhost:8763/app-user/api/v1/... .

我错过了一些配置吗?

您必须在 zuul 服务器属性中添加 zuul 路由:例如:

zuul:
   routes:
      accounts-web:#app name 
         url: http://localhost:8081 # app url

正确添加路由后,您将能够访问该 URL。

参考: https : //spring.io/guides/gs/routing-and-filtering/

要在路由中使用 eureka 应用程序名称,请添加如下路由:

zuul:
    routes:
        app-user: #app name
            path: /app-user/** #app-url
        app-user:
            serviceId: APP-USER #eureka serviceID

参考: https : //springbootdev.com/2018/02/03/microservices-declare-zuul-routes-with-eureka-serviceid-spring-cloud-zuul-eureka/

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM