1.1、依赖-初体验
1、添加依赖
<!-- spring cloud gateway 依赖 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway</artifactId> </dependency>
2、添加微服务的依赖
<!-- SpringCloud 微服务 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency>
3、在src/main/resources下添加bootstrap.yml
server: port: 8080 spring: application: name: gateway cloud: gateway: routes: # 系统模块 - id: guo-system uri: https://www.baidu.com predicates: - Path=/gateway filters: - StripPrefix=1
4、添加启动类测试
@SpringBootApplication public class GatewayApplication { public static void main(String[] args){ SpringApplication.run(GatewayApplication.class, args); } }
5、访问 http://localhost:8080/gateway 就会转发到 https://www.baidu.com/