SpringBoot使用Swagger3出现Unable to infer base url.This is common when using dynamic servlet

background

在spring boot中使用Swagger3,当访问http://localhost:8080/swagger-ui/index.html时报【Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway
insert image description here

reason

The reason for this pop-up window is that the data format returned by the swagger interface is inconsistent with the expected one. You can use it to http://localhost:8080/v3/api-docsview the returned format, which obviously does not meet the data requirements of swagger.
insert image description here
The correct data format is as follows
insert image description here

The reason for this result is that the project has added a unified result conversion, as follows

@RestControllerAdvice(annotations = RestController.class)
public class GlobalResponseAdvice implements ResponseBodyAdvice<Object> {
    
    }

Solution

You can specify the conversion project package on the annotation of RestControllerAdvice without converting swagger

@RestControllerAdvice(basePackages = "org.moss")
public class GlobalResponseAdvice implements ResponseBodyAdvice<Object> {
    
    }

finally accessible
insert image description here

Guess you like

Origin blog.csdn.net/q283614346/article/details/128456839