Bootstrap

No mapping for GET /swagger-ui.html报错

访问地址:http://127.0.0.1:8080/swagger-ui.html

 控制台报错如下:

好吧,没有找到

回顾刚才的操作,小编在config文件夹里添加了Swagger2Config,启动找不到;

如何解决?

1.实现

implements WebMvcConfigurer

2.实现

addResourceHandlers

接口

/**
* Swagger2配置
* @author
*/
@Configuration
@EnableSwagger2
@EnableWebMvc
public class Swagger2Config implements WebMvcConfigurer {
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {

			registry.addResourceHandler("/**").addResourceLocations(
					"classpath:/static/");
			registry.addResourceHandler("swagger-ui.html").addResourceLocations(
					"classpath:/META-INF/resources/");
			registry.addResourceHandler("/webjars/**").addResourceLocations(
					"classpath:/META-INF/resources/webjars/");
			WebMvcConfigurer.super.addResourceHandlers(registry);
	}

	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
				.apis(RequestHandlerSelectors.basePackage("com.xxxx.xxx"))
				.paths(PathSelectors.any()).build();
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("API文档").version("1.0").build();
	}
}

 重新启动服务后访问:

;