由于添加了一个http-passthrough服务,需要将服务配置到gateway中提供公网访问,于是在springCloud gateway 的yml中配置路由规则如下:
# 透传服务
- id: http-passthrough
uri: lb://http-passthrough
predicates:
- Path=/hp/**
问题:经过测试发现访问报404,请求url如下:
http://localhost:8728/hp/passThrough/sendToMQByDeviceUnique
经过排查才发现:由于自己在http-passthrough服务中并没有配置servlet context-path
两种解决方案:
第一种:在http-passthrough服务的yml中配置servlet context-path为/hp
servlet:
context-path: /hp
第二种:在 gateway 的yml中配置路径截取filters:
- StripPrefix=1(截取掉- Path中的第一级路径/hp)
# 透传服务
- id: http-passthrough
uri: lb://http-passthrough
predicates:
- Path=/hp/**
filters:
- StripPrefix=1