首先导入依赖,pom.xml为
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
这里有个需要注意的地方,gateway 依赖了webflux,所以要使用gateway就必须去除spring-boot-starter-web,gateway会在启动检查是否包含webflux和web,缺少webflux和有依赖web都会导致无法启动网关服务。