SpringCloud Gateway(八)
本文内容纲要:
-搭建SpringCloudGateway
搭建SpringCloudGateway
创建microservicecloud-springcloud-gateway-9528工程
pom文件依赖:
<dependencies>
<!--将微服务provider侧注册进eureka-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!--swagger-spring-boot-->
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>1.7.0.RELEASE</version>
</dependency>
<!--api接口-->
<dependency>
<groupId>com.yehui</groupId>
<artifactId>microservicecloud-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
yml文件
server:
port:9528
spring:
application:
name:springcloudgetway
cloud:
gateway:
discovery:
locator:
enabled:true
lowerCaseServiceId:true
routes:
#id标签配置的是router的id,每个router都需要一个唯一的id
-id:dept_client
#uri配置的是将请求路由到哪里,
uri:lb://microservicecloud-dept
predicates:
-Path=/dept_client/client/**#如果请求地址满足/microservicecloud-dept/**,则转发到microservicecloud-dept服务
filters:
-StripPrefix=2
eureka:
client:#客户端注册进eureka服务列表内
service-url:
defaultZone:http://localhost:7002/eureka/,http://localhost:7003/eureka/,http://localhost:7001/eureka/
instance:
prefer-ip-address:true
启动类
@SpringBootApplication
publicclassSpringCloudGateWayApp{
publicstaticvoidmain(String[]args){
SpringApplication.run(SpringCloudGateWayApp.class);
}
}
启动服务测试;
访问:http://localhost:9528/dept_client/client/dept/findAll
本文内容总结:搭建SpringCloudGateway,
原文链接:https://www.cnblogs.com/cxyyh/p/10693279.html