我正在使用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/v0 du的结果返回给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网关mainClass java
@SpringBootApplication
@EnableEurekaClient
public class GatewayApplication {发布于 2021-09-28 10:26:19
我最终通过在配置文件中添加cors-configuration来解决我的问题。
spring:
cloud:
gateway:
default-filters:
- DedupeResponseHeader=Access-Control-Allow-Origin
globalcors:
cors-configurations:
"[/**]":
allowCredentials: true
allowedOrigins: "*"
allowedHeaders: "Origin, X-Requested-With, Content-Type, Accept, Content-Length, TOKEN, Authorization"
allowedMethods: "GET, POST, PATCH, PUT, DELETE, OPTIONS"
maxAge: 3628800https://stackoverflow.com/questions/69345502
复制相似问题