011-spring cloud gateway-使用
阿新 • • 發佈:2018-11-12
一、pom增加
<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>
二、使用
啟動類無需任何設定,設定配置檔案
spring: application: name: gateway-service cloud: gateway: # discovery: #方式一、是否與服務發現元件進行結合,通過 serviceId(必須設定成大寫) 轉發到具體的服務例項。預設為false,設為true便開啟通過服務中心的自動根據 serviceId 建立路由的功能。 # locator: #路由訪問方式:http://Gateway_HOST:Gateway_PORT/大寫的serviceId/**,其中微服務應用名預設大寫訪問。 # enabled: true # routes: #方式二 使用lb負載均衡載入 # - id: USERSERVICE # uri: lb://USER-SERVICE:8762 # predicates: # - Path=/userapi/** # filters: # - StripPrefix=1 routes: #方式三 直接使用 域名地址 - id: USERSERVICE uri: http://localhost:8762 predicates: - Path=/userapi/** filters: - StripPrefix=1
參考程式碼:https://github.com/bjlhx15/spring-cloud-base/tree/master/spring-cloud-sleuth-study