配置文件
bootstrap.yml
spring:
application:
name: cloud-gateway
profiles:
active: dev
bootstrap-dev.yml
spring:
cloud:
nacos:
config:
server-addr: localhost:8848
namespace: 54fdd84f-44bb-45c1-b9c7-2b13bb4dca57
shared-configs:
- data-id: cloud-gateway.yml
group: DEFAULT_GROUP
refresh: true
cloud-gateway.yml
server:
port: 8888
spring:
application:
name: cloud‐gateway
cloud:
nacos:
discovery:
server‐addr: localhost:8848
namespace: 54fdd84f-44bb-45c1-b9c7-2b13bb4dca57
gateway:
discovery:
locator:
enabled: true
lower-case-service-id: true
routes:
- id: cloud-order
uri: lb://cloud-order
predicates:
- Path=/order/**
logging:
level:
org.springframework.cloud.gateway: debug
拦截器
@Slf4j
@Component
@Order(0)
public class CloudGlobalFilter implements GlobalFilter {
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
log.info("CloudGlobalFilter");
return chain.filter(exchange);
}
}
依赖
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<version>3.0.3</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>${spring-cloud-alibaba.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>${spring-cloud-alibaba.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>3.0.6</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
<scope>provided</scope>
</dependency>
</dependencies>