SpringBoot中使用Filter

某个SpringBoot项目,在application.yml中指定了context-path:

1
2
3
4
server:
port: 8998
servlet:
context-path: /shuang-api/

这样一来,该项目所有的接口,根访问路径就都成了 ip:prot/shuang-api

但有一个接口(比如k8s的探活),需要提供一个直接 ip:port/health/status这样的接口,如何才能做到?

方案一当然是把application.yml中的context-path去掉,给除/health/status之外的接口加上/shuang-api/

但如果该项目有100个接口,这样改显然不合理

调研了一些方案,

https://blog.csdn.net/weixin_30531261/article/details/79396202

https://segmentfault.com/a/1190000025152370

https://github.com/zhengxl5566/springboot-demo/tree/master/filter-demo

https://www.jianshu.com/p/4b38c6729d20

另外,是不是可以动态指定 context path?https://blog.csdn.net/qq_39314099/article/details/113499564

文章目录