首页 > 解决方案 > Swagger 3.0.0 + WebFlux:我的设置有什么问题或缺失?

问题描述

嗨!对不起我的英语,但这不是我的母语。我正在尝试制作一个项目来练习 webflux,但我无法让 Swagger 工作。我在 StackOverflow 和 Google 上进行了很好的搜索,但找不到解决方案。我也尝试查看SpringFox文档,但也许我不太明白。我决定向 StackOverflow 提出我的第一个问题:

我的项目设置中缺少什么以使 Swagger 工作?

build.gradle 根目录:

    buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:2.1.9.RELEASE"
    }
}

plugins {
    id "application"
    id 'java'
    id 'org.springframework.boot' version '2.1.9.RELEASE'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id "io.freefair.lombok" version "5.1.0"
}

dependencies {
    compile project(":contract")
}

mainClassName = 'com.pocwebflux.PocWebfluxApplication'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
    jcenter()
}

allprojects {
    apply plugin: 'java'
    apply plugin: 'io.spring.dependency-management'
    apply plugin: 'io.freefair.lombok'
    apply plugin: 'org.springframework.boot'

    group = 'com.example'
    version = "1.0.0-SNAPSHOT"

    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11

    repositories {
        mavenCentral()
    }

    test {
        useJUnitPlatform()
    }

    dependencyManagement {
        imports {
            mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.9.RELEASE"
        }
    }

    dependencies {
        implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
        implementation 'org.springframework.boot:spring-boot-starter-webflux'
        implementation "io.springfox:springfox-boot-starter:3.0.0"
        compile 'io.springfox:springfox-swagger-ui:3.0.0'
        compileOnly 'org.projectlombok:lombok'
        annotationProcessor 'org.projectlombok:lombok'
        testImplementation 'org.springframework.boot:spring-boot-starter-test'
        testImplementation 'io.projectreactor:reactor-test'
        testImplementation 'io.projectreactor:reactor-test'
        testImplementation 'org.mockito:mockito-junit-jupiter'
        testImplementation 'org.junit.jupiter:junit-jupiter-engine'
        testImplementation 'org.junit.jupiter:junit-jupiter-api'
        testImplementation 'org.junit.jupiter:junit-jupiter-engine'
        testImplementation 'org.junit.jupiter:junit-jupiter-params'
    }

    test {
        useJUnitPlatform()
    }
}

build.gradle 合约层:

dependencies {
    implementation project(':impl')
}

impl层:没有

我仍然没有任何东西只实现带有测试端点的控制器,只是为了看看招摇是否有效:

客户端控制器

我按照文档创建了这个类,但我不确定在哪里使用它:

SwaggerUiWebFluxConfigurer

设置中会缺少什么?

有人可以澄清我的问题吗?非常感谢。

我忘了说构建项目正常并且服务上升并在邮递员中返回200。

标签: javaspringspring-bootswaggerspring-webflux

解决方案


经过一系列的尝试和研究,我发现我的问题出在 Intellij 上。我遇到了现金问题,我没有下载依赖项。我做了一个 ./gradlew clean,删除了所有 springfox 和 swagger 库。我去了项目的根目录并删除了“.idea”文件夹。我再次下载了依赖项,其中包括:

implementation group: 'org.springframework.plugin', name: 'spring-plugin-core', version: '2.0.0.RELEASE'

完毕!

现在它正在工作。

在此处输入图像描述


推荐阅读