首先在使用前先将所需的jar导入:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
官方文档上说了,在使用zuul中,需要eureka-client就是客户端,而不用eureka-server。
然后在启动类加上@EnableZuulProxy注解,这个注解是包含了eureka所需的注解,所以只讲eureka的包导入就好了,eureka不用这个注解注册@EnableDiscoveryClient。
然后是配置文件中,该使用的配置:
server.port: 8064
eureka:
client:
serviceUrl:
defaultZone: http://localhost:80/eureka/
spring:
application:
name: spring-boot-gateway-zuul
zuul:
#ignoredServices: '*' #这里所谓的拒绝,是在通过zuul访问其他微服务的时,是不成功的&#