spring boot 2.3.5
spring cloud Hoxton.RELEASE
使用gateway需要排除掉boot的web依赖,不然会启动报错
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
启动类
@SpringBootApplication
@EnableEurekaClient
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class,args);
}
}
配置路由方式一:yml文件配置
server:
port: 8094
spring:
application:
name: base-gateway-service
cloud:
gateway:
routes:
- id: demo #相当于主键 多个需要保证唯一
uri: ht