pom
org.springframework.cloud spring-cloud-starter-eureka 1.4.7.RELEASE org.springframework.cloud spring-cloud-starter-zuul 1.4.7.RELEASE
配置文件
server:
port: 9200
spring:
application:
name: gateway
eureka:
client:
register-with-eureka: true # 注册
fetch-registry: true # 拉取
service-url: # 地址
defaultZone: http://localhost:9000/eureka/
启动类
@SpringBootApplication
@EnableZuulProxy
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class);
}
}
测试
全部运行,通过网关的端口访问消费者URL:http://localhost:9200/consumer
成功!
配置文件
zuul:
routes: # 配置旧路径映射新路径
provider:
serviceId: provider
path: /student/**
consumer:
serviceId: consumer
path: /query/**
ignored-services: "*" # 关闭旧路径
测试
http://localhost:9200/query
成功!
配置文件
zuul:
routes:
provider:
serviceId: provider
path: /student/**
consumer:
serviceId: consumer
path: /query/**
ignored-services: "*"
prefix: /p # 前缀
测试
http://localhost:9200/p/query
成功!



