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】
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-docs
view the returned format, which obviously does not meet the data requirements of swagger.
The correct data format is as follows
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