swagger 采坑日记
今天在写Springboot的项目时,自定义了一个注解器,用来解析mvc的参数
把注解器加入到HandlerMethodArgumentResolver
列表中后,发现Swagger访问不了
原因是找不到资源文件
解决方法:
重写addResourceHandlers,并且把资源路径加进去
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
@Override
protected void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(new RequestFieldHandler());
}
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/swagger-ui.html");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}