【发布时间】:2021-11-19 12:54:28
【问题描述】:
我正在使用 Spring Cloud(Hoxton.SR10) 和 Spring Boot (2.2.6.RELEASE)
我在 Eureka 服务器 8761 中注册了我的服务
我有一个网关服务来管理路由(目前没有任何安全措施)
# profil DEV
---
spring:
profiles: dev
cloud:
gateway:
routes:
- id: pr-api-id
uri: http://localhost:8086/
predicates:
- Path=/api/**
这是 pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
<!-- Spring cloud eureka client -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
当我打电话给localhost:9092/api/v0(我在localhost:8086/v0 上有一个工作正常的服务)应该将localhost:8086/v0du 的相同结果返回给spring cloud gateway的路由
但我收到 http 错误 404
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Sep 27 12:46:20 CEST 2021
There was an unexpected error (type=Not Found, status=404).
No message available
网关主类 java
@SpringBootApplication
@EnableEurekaClient
public class GatewayApplication {
【问题讨论】:
-
根据您的帖子,网关正在将请求发送到 localhost:8086/api/v0。网关默认不修改请求。您需要更改路径。 StripPrefix 1 过滤器应该可以工作
-
感谢您的回复,但它不起作用路线:-id:pr-api-id uri:localhost:8086 谓词:-Path=/api/** 过滤器:-StripPrefix=1
标签: spring spring-boot spring-cloud spring-cloud-gateway