java - Spring Boot Zuul API Gateway 返回 404 响应
问题描述
我正在尝试设置 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 配置:
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/...
会收到一个。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
推荐阅读
- indexing - 如何在 MonetDB 中快速更改 (DELSERT) 表中使 DELETE 更快?
- reactjs - 尝试使用从 CDN 提供的包时,Typescript 抛出错误“未定义名称”
- python - 如何将 ROS msg 从一个 python 发布到另一个
- node.js - ElasticSearch-js { body } 未定义
- python-3.x - 按键时停止鼠标事件
- css - 如何在材质 ui makeStyles 中使用 @supports css 规则?
- java - 我在比较两个作为字符串的对象元素时遇到问题
- android - Android 模拟器在 Ubuntu 20.04 上非常慢
- c# - 错误请求被中止:无法创建 SSL/TLS 安全通道。仅在 Windows Server 2012 上
- java - Android Studio 在 ubuntu 系统上因 jre 致命错误而崩溃