swagger-ui.html 在上传文件类微服务中找不到

【问题】

使能了 @EnableSwagger2 ,检查各处都没有问题。

  但访问http://localhost:19900/swagger-ui.html#/

  的时候始终报404。

  用同样方法在其他微服务中都没有问题。

 

【问题原因】

  猜想:可能是上传文件的传参和swagger原有生成机制冲突

 

【解决方案】

1、在Application中使能@EnableWebMvc 

@EnableWebMvc
@EnableSwagger2
public class FileUploadApplication {
    public static void main(String[] args) {
        SpringApplication.run(FileUploadApplication.class,args);
    }
}

2、添加WebConfig文件 

package com.jingfatech.upload.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * webmvc 打开swagger
 *
 * @author ppmicro
 * @date 2020/6/20 11:40
 */
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {
    @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/");
        super.addResourceHandlers(registry);
    }
}

做了上面两步,问题解决。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章