关于spring springMVC整合swagger2 Unable to infer base url. This is common when using dynamic servlet...

在Spring SpringMVC环境中集成Swagger2时,访问swagger-ui.html遇到'Unable to infer base url'警告。问题通常由于动态Servlet注册或API位于API Gateway后。解决方法是检查SpringMVC过滤规则,可能需要添加匹配所有路径的配置,例如添加/mvc:resources 映射来允许访问Swagger2的静态资源,以避免404错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在spring springMVC整合swagger2,完成访问swagger-ui.html的时候出现

Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually:

其实出现这个可能有不少原因:但是最可能的是因为访问swagger-ui.html的时候,swagger-ui.html还会向你的服务器发出4个请求,请求你的相关信息,也就是你的controller包下的controller相关内容,这4个请求报了404所以弹出这个。

大部分人出现这个是因为springMVC的过滤原则设置的是*.do或者是*.xxx其它,但是swagger-ui.html的这4个请求是不带.xxx结尾的,所以最简单解决方案:修改springMVC配置:加一个带/的配置,修改之后可能其它的会冲突了,那也只能你自己去改,自己的项目,毕竟自己最了解。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值