spring cloud中使用zuul+eureka, zuul路由不到配置了context-path的客户端

spring cloud中使用zuul+eureka, zuul路由不到配置了context-path的客户端

client端代码

application.yml

server:
  port: 2222
  context-path: /client  #这里注释掉就正常了

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8888/eureka/

src\main\resources\static\hello.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>hello</title>
</head>
<body>
hello!!!!!!!!!!!!!!!!!!!!!!!!!
</body>
</html>

zuul端代码

application.yml

spring.application.name=gateway
server.port=5555

zuul.routes.client.path=/client/**
zuul.routes.client.serviceId=client

eureka.client.serviceUrl.defaultZone=http://localhost:8888/eureka/

访问 localhost:5555/client/hello.html,页面报404找不到.

如果将client端的context-path配置注释掉,页面就能正常访问.

请问在配置context-path的情况下,要怎么修改才能访问到页面

阅读 19.7k
1 个回答

自己解决了
在zuul端加上stripPrefix为false就行了

zuul.routes.client.path=/client/**
zuul.routes.client.serviceId=client
zuul.routes.client.stripPrefix=false
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题