目录
1.工程目录
2.单机使用
2.1依赖
zuul网关本身也是一个微服务,需要注册到eureka中,完整依赖如下。
版本在父项目中统一定义
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
</dependencies>
2.2配置文件
proxy-1为代理名称
/proxy-1/**为代理请求路径(此类型路径会被代理)
serviceId为代理服务名称,注册在eureka中的服务名称
spring:
application:
name: springcloud-zuul
server:
port: 9410
eureka:
instance:
instance-id: springcloud-zuul1
appname: ${spring.application.name}
prefer-ip-address: true
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 5
client:
service-url:
defaultZone: http://test1:9110/eureka/,http://test2:9120/eureka/
zuul:
routes:
proxy-1:
path: /proxy-1/**
serviceId: springcloud-common
2.3主启动类添加@EnableZuulProxy
@SpringBootApplication
@EnableEurekaClie