1. The introduction of the following dependent
<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-netflix-zuul</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
2. Start class, add the following comment @EnableZuulProxy
@SpringBootApplication @EnableZuulProxy public class ApiZuulApplication { public static void main(String[] args) { SpringApplication.run(ApiZuulApplication.class, args); }}
Original access of goods and services as follows:
Gateway Access by: the address to access the gateway address, and add the service name of goods and services as follows:
Complete unification is completed by the sending gateway
And you can add custom route map in the startup class
# / the Order-Service / API / v1 / the Order / the Save user_id = 2 & product_id = 1? # custom route map Zuul: routes: the Order -service: / apizuul / the Order / ** Product-Service: / apizuul / Product / ** # unified entrance to the above configuration, the other entry is ignored ignored-Patterns: / * - Service / ** # handle http request header is empty issue sensitive-headers:
This can be done without exposing the true path to the user's request