#介绍
2 使用
2.1引入依赖
<!-- zuul的依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
<version>1.4.6.RELEASE</version>
</dependency>
2.2编写配置
server:
port: 9527
spring:
application:
name: springcloud-zuul
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:7001/eureka/,http://127.0.0.1:7002/eureka/,http://127.0.0.1:7003/eureka/
instance:
#可以将localhost改为(klz.com域名)
#我这里不想改C:\Windows\System32\drivers\etc\host文件的配置所以访问的时候把localhost当成klz.com使用
instance-id: klz.com
prefer-ip-address: true
info:
app.name: klz-springcloud
company.name: klz.com
zuul:
routes:
mydept.serviceId: springcloud-provider-dept
mydept.path: /mydept/** #将服务名改一个名字代替服务名
ignored-services: springcloud-provider-dept #忽略服务名,不能用服务名访问了
prefix: #设置公共前缀
2.23启动类上添加注解
@EnableZuulProxy
package com.common.springcloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
@SpringBootApplication
@EnableZuulProxy //启动zuul代理
public class ZuulApplication_9527 {
public static void main(String[] args) {
SpringApplication.run(ZuulApplication_9527.class, args);
}
}
2.24测试
开启7001.8001,80,9527