gateway context-path不生效问题

来源:7-14 验证网关微服务功能可用性

就叫香菜算了

2021-07-31

如题,本来想测试gateway可用性,启动了所有的服务,发现gateway模块在admin中显示down,最后发现是启动的时候,context-path不生效.

http://127.0.0.1/gateway/actuator 404
http://127.0.0.1/actuator  就能访问到

难道就我一个人碰见了这个问题?大家都没问题?
查了一下资料有些人说是新增一个router让自己访问自己…
但是想请教一下老师有没有更好的解决方法

写回答

4回答

就叫香菜算了

提问者

2021-08-01

问题已解决 如图

//img.mukewang.com/szimg/61057a2c09074dec19230902.jpg

1
1
就叫香菜算了
gateway不需要context_path并且直接/actuator就行
2021-08-01
共1条回复

燎丶Trance

2021-09-15

解决方案:


@Bean
public WebFilter contextPathWebFilter(ServerProperties serverProperties) {
    String contextPath = serverProperties.getServlet().getContextPath();    
    return (exchange, chain) -> {
        ServerHttpRequest request = exchange.getRequest();        
        if (request.getURI().getPath().startsWith(contextPath)) {            
        return chain.filter(
                exchange.mutate()
                .request(request.mutate().contextPath(contextPath).build())
                .build());
        }        return chain.filter(exchange);
    };
}


在请求的时候, 添加上去

0
0

就叫香菜算了

提问者

2021-07-31

另外附上一张gateway启动截图以及能被admin监控到的服务截图(拜谢)

//img.mukewang.com/szimg/61056bc409fab13925600705.jpg

//img.mukewang.com/szimg/61056bc40992d32125100644.jpg


0
1
就叫香菜算了
原因我是知道了,因为webflux没有DispatchServlet,所以当然就不支持ContextPath,那这要咋做才能让admin监控到了
2021-07-31
共1条回复

就叫香菜算了

提问者

2021-07-31

其实主要想解决的是想把gateway和admin整合成功,代码直接复制的还是不行,感觉是不是因为就是因为前面没有项目名称,所以admin就没有监控到

0
0

Spring Cloud / Alibaba 微服务架构实战

从架构设计到开发实践,手把手实现

1210 学习 · 674 问题

查看课程