版权声明:转载请注明出处。 原文作者:Lily@g 原文链接: https://blog.youkuaiyun.com/weixin_42389328/article/details/82620900
我用的是springboot2.0.3 版本
下面看一下具体是怎么解决swagger不能访问的问题的。
在springboot 中WebMvcConfigurerAdapter类废弃不用了,可以通过继承WebMvcConfigurationSupport类代替WebMvcConfigurerAdapter类,也可以通过实现这个WebMvcConfigurer类代替WebMvcConfigurerAdapter。这里我是使用的是这个WebMvcConfigurationSupport类。
一、使用WebMvcConfigurationSupport这个类的时候静态文件会被拦截通过重写addInterceptors这个方法排除swagger的访问路径。如红色部分所示:
- swagger配置文件
@Configuration
@EnableSwagger2
public class Swagger2 {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.manager"))//基础包
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("家庭签约平台API文档