springboot集成swagger报404问题

springboot集成swagger报404问题

@Configuration
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurationSupport {

@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .pathMapping("/")
            .select()
            // swagger要扫描的controller包
            .apis(RequestHandlerSelectors.basePackage("fun.imcoder.cloud.controller"))
            .paths(PathSelectors.any())
            .build().apiInfo(new ApiInfoBuilder()
                    .title("springboot2.x集成swagger")
                    .description("springboot2.x集成swagger")
                    .version("1.0")
                    .contact(new Contact("imcoder", "http://www.imcoder.fun", "[email protected]"))
                    .build());
}

@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
    registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}

}

加入 addResourceHandlers 瞬间搞定。

猜你喜欢

转载自blog.csdn.net/weixin_43445815/article/details/114293616