Pri*_*wal 4 java cors spring-boot microservices api-gateway
我正在开发一个 Spring Boot 应用程序。其中有API-Gateway和三个微服务。当我从 UI 调用 API 时,它会抛出 CORS 错误。
错误:
访问控制允许来源标头包含多个值,但只允许一个
我已经在 API-Gateway 的 application.yml 中配置了 cors。
spring:
application:
name: api-gateway
cache:
type: redis
redis:
host: 'http://localhost'
port: 6379
cloud:
gateway:
globalcors:
corsConfigurations:
'[/**]':
allowedOrigins: "*"
allowedMethods: "*"
allowedHeaders: "*"
eureka:
client:
eureka-server-d-n-s-name: my.dns
eureka-service-url-Context: eureka
fetch-registry: false
region: ap-south-1b
register-with-eureka: false
use-dns-for-fetching-service-urls: true
datacenter: cloud
ribbon:
eureka:
enabled: false
server:
port: 8765
zuul:
routes:
order-service:
url: 'http://localhost:8088'
product-service:
url: 'http://localhost:8084'
user-service:
url: 'http://localhost:8082'
Run Code Online (Sandbox Code Playgroud)
除此之外,我还在每个微服务中配置了 CORS。如果我直接调用微服务,而不是通过 API-Gateway 调用 API,它工作得很好。
访问控制允许来源标头包含多个值,但只允许一个值表明您正在发送多个不符合预期的标头。
此处,您在 API 网关和导致问题的每个微服务上配置了 CORS,为避免该问题,您可以仅在 API 网关上或在每个微服务中配置 CORS 配置。
| 归档时间: |
|
| 查看次数: |
7267 次 |
| 最近记录: |