Spring Boot 2.x集成Swagger2问题
具体的操作集成操作参看大佬的文章使用Swagger2构建强大的API文档,这里不再多说(确实没别人写的好)。下面主要说一下遇到的问题:
出现Unable to infer base url
具体是启动项目后弹框出现如下:
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:
这里具体出现此问题就是:需要在SpringBoot的启动Application前面加上 @EnableSwagger2注解;
@EnableSwagger2注解显示找不到
这里需要在应用主类中增加@EnableSwagger2Doc注解,特别注意包引用,这里提供一个demo
package com.example.hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2
@SpringBootApplication
public class HelloApplication {
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
}
网友评论