001. POM Configuration
Increased Eureka Client, Zuul dependency, and spring cloud dependency management compared to the normal spring boot project
<Dependencies> <Dependency> <groupId>Org.springframework.cloud</groupId> <Artifactid>Spring-cloud-starter-eureka</Artifactid> </Dependency> <Dependency> <groupId>Org.springframework.cloud</groupId> <Artifactid>Spring-cloud-starter-zuul</Artifactid> </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>
002, enable to Zuul Proxy
@SpringBootApplication @enablezuulproxy // Enable API Gateway Public class apigatewayzuulapplication { publicstaticvoid main (string[] args) { Springapplication.run (apigatewayzuulapplication. class , args);} }
003, src/main/resources under the configuration file application.yml
Spring: application: name:api-gateway-zuulserver: Port:5001eureka: client: serviceurl : defaultzone:http://discovery:1000/eureka/
Steps to use:
A) Start the Eureka Server service Eureka-server
b) Start the Hello service Hello-service-provider (can start multiple)
c) Start Api-gateway-zuul Service
d) access to Hello service via Http://localhost:5001/hello-service-provider/hello
004. Custom Service Path
Zuul: routes: SayHello: # can write casually, on the Zuul above the only can, when the value here = Service-id, Service-id can not write. Path :/sayhello/** # The path you want to map to Service-id:hello-service-provider # Eureka in Serviceid
The service of Hello Service can be accessed via Http://localhost:5001/sayhello/hello at this time
005, ignore the specified service does not proxy
Zuul: Ignored-services:hello-service-provider
The Hello-service-provider service will not be proxied at this time
007API Gateway Service Zuul