Springfox swagger-ui 3.0.0 不调出 swagger-ui.html 页面 [英] Springfox swagger-ui 3.0.0 does not bring up swagger-ui.html page

查看:125
本文介绍了Springfox swagger-ui 3.0.0 不调出 swagger-ui.html 页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Springboot 中使用 springfox swagger-ui,但文件上传按钮未启用分段上传.我尝试升级到 springfox-swagger-ui 3.0.0 但这甚至没有打开 swagger-ui 页面.有没有办法获得文件上传按钮?

我的 API 调用如下所示:

@RequestMapping(value = "/foo", method = RequestMethod.POST,consumes = MediaType.MULTIPART_FORM_DATA_VALUE)公共响应实体方法(@RequestParam(文件")多部分文件文件,@RequestParam(id")字符串id){

....}

springfox-swagger-ui 2.10.5 的当前问题

 我的 pom.xml 是:<属性><java.version>1.8</java.version><io.springfox.version>3.0.0</io.springfox.version></属性><依赖><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>${io.springfox.version}</version></依赖><依赖><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.10.5</version></依赖><依赖><groupId>io.springfox</groupId><artifactId>springfox-data-rest</artifactId><version>${io.springfox.version}</version></依赖><依赖><groupId>io.springfox</groupId><artifactId>springfox-boot-starter</artifactId><version>${io.springfox.version}</version></依赖>

解决方案

来自:

I am using springfox swagger-ui with Springboot but the fileUpload button is not enabled for multipart upload. I tried upgrading to springfox-swagger-ui 3.0.0 but that does not even bring up the swagger-ui page. Is there any way to get the file upload button ?

My API call looks like this :

@RequestMapping(value = "/foo", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)

public ResponseEntity<ByteArrayResource> method(@RequestParam("file") MultipartFile file, @RequestParam("id") String id) {

.... }

Current issue with springfox-swagger-ui 2.10.5

    My pom.xml is : 
    <properties>
      <java.version>1.8</java.version>
      <io.springfox.version>3.0.0</io.springfox.version>
    </properties>
    <dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>${io.springfox.version}</version>
    </dependency>
    <dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.10.5</version>
    </dependency>
    <dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-data-rest</artifactId>
    <version>${io.springfox.version}</version>
    </dependency>

    <dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>${io.springfox.version}</version>
    </dependency>

解决方案

From: http://springfox.github.io/springfox/docs/current/#migrating-from-existing-2-x-version

there are things need to do:

1. add springfox-boot-starter to POM , remove old dependencies from POM: springfox-swagger2 and springfox-swagger-ui

    <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
</dependency>

2. Remove the @EnableSwagger2 annotations

@Configuration
// remove @EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2).select()
        .apis(RequestHandlerSelectors.basePackage(UserManagementImpl.class.getPackage().getName()))
        .paths(PathSelectors.any()).build();
    }
}

3. using @RequestPart("files") on request

@ApiOperation(value = "files", notes = "upload user emails from CSV and email content from json and send out")
    @PostMapping(path = "/users/uploadUserEmailsAndSend", consumes = { "multipart/form-data" })
    @ResponseBody
    ResponseEntity<UploadUsersResDTO> uploadUserEmailsAndSend(@RequestPart("files") MultipartFile[] filesUpload){

    CSVParser csvParser = null;
    BufferedReader fileEmailsReader = null;
    BufferedReader fileEmailMessageReader = null;
    MultipartFile fileCSV = null;
    MultipartFile fileJson = null;

    try {
        if (filesUpload[0].getOriginalFilename().toLowerCase().endsWith("csv")) {
            fileCSV = filesUpload[0];
            fileJson = filesUpload[1];
        } else {
            fileCSV = filesUpload[1];
            fileJson = filesUpload[0];
        }
        // more codes ....
}

4. access swagger at: http://localhost:8080/swagger-ui/

这篇关于Springfox swagger-ui 3.0.0 不调出 swagger-ui.html 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆