<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-netflix-eureka-clientartifactId>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-netflix-zuulartifactId>
dependency>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0modelVersion>
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>2.2.6.RELEASEversion>
<relativePath/>
parent>
<groupId>com.go.cngroupId>
<artifactId>zuul-serverartifactId>
<version>0.0.1-SNAPSHOTversion>
<name>zuul-servername>
<properties>
<java.version>1.8java.version>
<spring-cloud.version>Hoxton.SR3spring-cloud.version>
properties>
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starterartifactId>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-netflix-eureka-clientartifactId>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-netflix-zuulartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-testartifactId>
<scope>testscope>
dependency>
dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-dependenciesartifactId>
<version>${spring-cloud.version}version>
<type>pomtype>
<scope>importscope>
dependency>
dependencies>
dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
plugins>
build>
project>
@EnableZuulProxy
server:
port: 80
spring:
application:
name: zuul-server
eureka:
client:
service-url:
defaultZone: http://euk1.com:7000/eureka/
provider:
ribbon:
NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule # 使用随机策略
/服务名/**
依旧可用来访问;zuul:
routes:
consumer: /consumer-api/**
# 或者
# serviceId: consumer
# path: /consumer-api/**
zuul:
routes:
xx:
path: /xx/**
url: http://www.baidu.com
search:
path: /search/**
url: http://www.baidu.com
zuul:
ignored-services: provider
zuul:
prefix: /api/v1
# 是否带上前缀请求,代理前缀默认会从请求路径中移除,通过该设置关闭移除功能,
# 默认为 true-不带前缀
# false-带前缀相当于被代理项目要有这个前缀
strip-prefix: false
添加依赖:默认已经集成了actuator
配置文件调整:暴露端点;
management:
endpoint:
health:
enabled: true
show-details: always
routes:
enabled: true
endpoints:
web:
exposure:
include: '*'
curl http://localhost/actuator/routes
: 可以查看路由的映射结果;例如上边 前缀配置的生效范围就可以使用此路径进行查看:
{
"/api/v1/consumer-api/**":"consumer",
"/api/v1/xx/**":"http://www.baidu.com",
"/api/v1/search/**":"http://www.baidu.com",
"/api/v1/provider/**":"provider",
"/api/v1/consumer/**":"consumer"
}