【解决问题】Swagger-ui页面报错:Unable to infer base url. This is common when using**,Swagger与lombok冲突

一、错误描述

在这里插入图片描述

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: 

我的操作只是将master代码合并到个人分支上,然后跑本地代码就出现这个错误,master代码正常运行,网上的解决方式大致以下几种

  • 1.切换swagger版本,从2.9.2到2.7.0,切换版本的同时清除浏览器缓存
  • 2.在启动类加@EnableSwagger2
  • 3.拦截器过滤swagger权限

不过以上方式么有解决我的问题,最后将master与本地分支代码进行一一比对,因为我修改的代码比较少,在帅行师哥的帮助下找到原因

二、找到原因

在这里插入图片描述
原因:

1.lombok注解@Accessors(chain=true):作用让setter方法返回当前对象

2.继承BaseEntity,BaseEntity封装了数据库常用字段比如,id,加入getter和setter方法,setter方法返回void

3.因为在继承了BaseEntity之后又加入了id,此时产生冲突
@Accessors(chain=true)让id的setter方法返回当前对象
BaseEntity让id的setter方法返回id值

查资料说,@Accessors(chain=true)会和swagger的注解产生了冲突,导致swagger获取不到实体类的属性,具体原因还有待研究,大佬们可以在评论区留言哦

三、解决方法

  • 1.去掉lombok 注解@Accessors(chain = true)
  • 2.去掉自定义的private String id;

这样就不产生冲突了,所以以后用lombok的时候要小心一点了
附上@Accessors(chain = true)详细解读

猜你喜欢

转载自blog.csdn.net/shang_0122/article/details/107136070