spring cloud 我能找到的解决办法就只有这个:
spring:
application:
name: gateway-server
cloud:
gateway:
globalcors:
corsConfigurations:
'[/**]':
allowedOrigins:
# 跨越规则,指定了下方可以跨域的浏览地址之后,该浏览地址通过ajax访问gateway,此处是8100,然后gateway在通过映射找到需要访问的服务
- "*" # 不支持通配符方式,但是支持一个整的*号
allowedMethods:
- GET
实现效果 : 访问8091的html页面-> 8091中使用ajax访问http://localhost:8081/user/2
需要修改为 http://localhost:8100/user/2; 8100是Gateway的地址
因为网关中做了映射,所有8100/user/2会访问到8081/user/2;
别的就都是写的类了;