<!-- SpringCloud Gateway -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
# Tomcat
server:
port: 8080
# Spring
spring:
application:
# 应用名称
name: gateway
profiles:
# 环境配置
active: dev
cloud:
gateway:
routes: #网关路由配置
- id: userservice #路由id,自定义,必须唯一
url: lb://userservice # 路由的目标地址 lb就是负载均衡,后面跟服务名称
predicates: #路由断言,也就是判断请求是否符合路由规则的条件
- Path=/user/** # 这个是按照路径匹配,只要以/user/开头就符合要求
nacos:
discovery:
# 服务注册地址
server-addr: 127.0.0.1:8848
config:
# 配置中心地址
server-addr: 127.0.0.1:8848
# 配置文件格式
file-extension: yml
PredicatesFactory
GatewayFilter是网关中提供的一种过滤器,可以对进入网关的请求和微服务返回的响应做处理。
官网地址:
https://docs.spring.io/spring-cloud-gateway/docs/current/reference/html/#gatewayfilter-factories

浏览器禁止请求的发起者与服务端发生跨域ajax请求,请求被浏览器拦截的问题。
网关处理跨域采用的同样是CORS方案