Zuul是一个网关,主要就是让客户端访问Zuul、然后Zuul访问所有微服务
1.Jar
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.12.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
</dependencies>
2.application.properties
server.port=808
eureka.instance.hostname=localhost
eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:8761/eureka/
#Zuul项目项目名
spring.application.name=api-geteway
#使用user就代表USER-SERVICE
zuul.routes.USER-SERVICE=/user/**
ribbon.eureak.enabled=false
#使用ribbon负载均衡
USER-SERVICE.ribbon.listOfServers=http://localhost:8080,http://localhost:8083
3.启动文件
@SpringBootApplication
//组合注解
@EnableZuulProxy
public class StartProject {
public static void main(String[] args) {
SpringApplication.run(StartProject.class, args);
}
}