Create a gateway project
Chart added after the micro gateway services
Create a project
POM file
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Modify the configuration file
The /src/main/resources/application.properties file in the project directory rename application.yml, properties and yml configuration format configuration format is equivalent, but yml configuration format can be used to better distribution center, so we use yml configuration format.
Test the gateway project
application.yml profile contents amended as follows:
server:
port: 9000
spring:
cloud:
gateway:
routes:
- id: first_route
uri: https://github.com/sunweisheng
predicates:
- Path=/test
- port: Port Gateway Services
- routes: route set
- The only marked routes: id
- uri: routing destination address
- predicates: routing conditions, if true then routed to the uri
kind of predicates (as well as filters) Many refer to the Spring Cloud Gateway's official website
Start test project
Access 127.0.0.1:9000/test
Source
Github repository: https: //github.com/sunweisheng/spring-cloud-example