首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring云网关路由不起作用

Spring云网关路由不起作用
EN

Stack Overflow用户
提问于 2021-09-27 11:02:57
回答 1查看 311关注 0票数 0

我正在使用Spring Cloud(Hoxton.SR10)和Spring Boot (2.2.6.RELEASE)

我在Eureka服务器8761中注册了我的服务

我有一个网关服务来管理路由(暂时没有任何安全性)

代码语言:javascript
复制
# profil DEV
---
spring:
  profiles: dev

  cloud:
    gateway:
      routes:
        - id: pr-api-id
          uri: http://localhost:8086/
          predicates:
           - Path=/api/**

这是pom.xml

代码语言:javascript
复制
<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

代码语言:javascript
复制
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

代码语言:javascript
复制
@SpringBootApplication
@EnableEurekaClient
public class GatewayApplication {
EN

回答 1

Stack Overflow用户

发布于 2021-09-28 10:26:19

我最终通过在配置文件中添加cors-configuration来解决我的问题。

代码语言:javascript
复制
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: 3628800
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69345502

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档