最近在学习spring cloud,使用zuul过程中发现地址并没转发成功,页面一直报错404.
使用的Spring cloud版本为最新版Greenwich
zuul中配置文件内容是
server:
port: 8180
spring:
application:
name: zuul-test
zuul:
routes:
hello:
path: /hello/**
url: http://localhost:9180/
期望的是当web请求http://localhost:8180/hello?name=world 时能跳转到http://localhost:9180/hello?neam=world 打印出"hello world",然而事实上并没有,出错,页面提示404.
开始以为是Spring cloud版本太高,就把纯洁的微笑博客中的demo下载下来测试,发现依然如此。
怀疑zuul的请求是直接跳转到http://localhost:9180/ 但是没有加上上下文"hello",所以将配置更改如下:
server:
port: 8180
spring:
application:
name: zuul-test
zuul:
routes:
hello:
path: /hello/**
url: http://localhost:9180/hello
请求跳转成功。
毕竟是自己的猜测,还是需要代码支持,所以断点,调试源码进入查看.
在org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter#run方法中通过
String