spring cloud gateway

pom

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-hystrix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>

 pom注意事项

必须去除mvc依赖

如果是springboot去除 spring-boot-starter-web 

启动项


@SpringCloudApplication
public class CousulgatewayApplication {

public static void main(String[] args) {
SpringApplication.run(CousulgatewayApplication.class, args);
}

配置文件

server:
port: 8083

#服务名
spring:
application:
name: gateway-service
cloud:
gateway:
routes:
- id: consulserver
# 重点!/info必须使用http进行转发,lb代表从注册中心获取服务
uri: lb://consulserver
predicates:
# 重点!转发该路径!,/userapi/**,
- Path=/consulserver/**
# http://localhost:6601/userapi/user/users/2, 必须加上StripPrefix=1,否则访问服务时会带上userapi
#而不是我们期望的去掉userapi,只保留**部分
filters:
- StripPrefix=1
discovery:
locator:
enabled: true
consul:
host: localhost
port: 8500
discovery:
register: false
参考文件https://blog.csdn.net/russle/article/details/80962066

 https://blog.csdn.net/qq_36752632/article/details/79656716

 

posted on 2018-11-28 17:09  ttke  阅读(259)  评论(0编辑  收藏  举报