简体   繁体   中英

No primary or default constructor found for interface org.springframework.web.server.ServerWebExchange

I have added swagger support to a microservice written in spring-boot. I am getting below error

HTTP ERROR 500 org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: No primary or default constructor found for interface org.springframework.web.server.ServerWebExchange

URI:    /docs/swagger-ui.html
STATUS: 500
MESSAGE:    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: No primary or default constructor found for interface org.springframework.web.server.ServerWebExchange
SERVLET:    dispatcherServlet
CAUSED BY:  org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: No primary or default constructor found for interface org.springframework.web.server.ServerWebExchange
CAUSED BY:  java.lang.IllegalStateException: No primary or default constructor found for interface org.springframework.web.server.ServerWebExchange
CAUSED BY:  java.lang.NoSuchMethodException: org.springframework.web.server.ServerWebExchange.<init>()

and here is the gradle file of my project!

plugins {
  id 'java-library'
  id 'idea'
  id 'io.franzbecker.gradle-lombok' version '4.0.0'
  id 'jacoco'
  id 'org.sonarqube' version '3.0'
  id 'com.github.spacialcircumstances.gradle-cucumber-reporting' version '0.1.22'
  id 'com.gorylenko.gradle-git-properties' version '2.0.0'
  id "org.springframework.boot"
  id "com.github.johnrengelman.processes" version "0.5.0"
  id "org.springdoc.openapi-gradle-plugin" version "1.3.2"
}

archivesBaseName = 'gates-compnaygate'
sourceCompatibility = 11
targetCompatibility = 11
apply from: "$gradleDir/sonar.gradle"
apply from: "$gradleDir/docker.gradle"
apply from: "$gradleDir/jacoco.gradle"
apply from: "$gradleDir/integration-test.gradle"

apply from: "../gradle/contracts.gradle"

dockerPlugin {
  applicationName = archivesBaseName
}

bootJar {
  archiveFileName = "${archivesBaseName}.jar"
}

contracts {
  basePackageForTests = "${group}.gates.compnaygate.contracts"
  testFramework = 'JUNIT5'
  testMode = 'EXPLICIT'
  baseClassMappings {
    baseClassMapping(".*rest.*", "${group}.gates.compnaygate.contract.RestBase")
    baseClassMapping(".*messaging.*", "${group}.gates.compnaygate.contract.MessagingBase")
  }
}

test {
  useJUnitPlatform {
    excludeTags 'integration', 'component'
  }
}

repositories {
  mavenLocal()
  maven {
    url = 'https://nexus.company-conv.com/repository/conv-deps/'
  }
}

componentTest {
  doFirst {
    systemProperty 'contractTestRepositoryRoot', "$nexusRepositoryUrl/contract-releases/,$nexusRepositoryUrl/contract-snapshots/"
  }
}

dependencyManagement {
  imports {
    mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Hoxton.SR8'
  }
}

dependencies {

  configurations {
    // exclude Tomcat use Netty instead
    compile.exclude module: 'spring-boot-starter-tomcat'
    compile.exclude module: 'spring-webmvc'
    compile.exclude module: 'spring-boot-starter-web'
  }

  implementation('org.springdoc:springdoc-openapi-ui:1.5.9')
  implementation('org.springdoc:springdoc-openapi-webmvc-core:1.5.9')
  implementation('com.company.conv:common-web:0.8.0'){
    exclude group: 'org.springframework', module: 'spring-webmvc'
    exclude group: 'org.springframework.boot', module: 'spring-boot-starter-web'
  }

  implementation(
    'com.company.conv:common-log:0.1.8',
    'com.github.ben-manes.caffeine:caffeine',
    'com.github.jknack:handlebars:4.1.2',
    'org.apache.commons:commons-collections4:4.3',
    'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client',
    'org.springframework.cloud:spring-cloud-starter-stream-kafka',
    'org.springframework.cloud:spring-cloud-starter-aws',
    'org.springframework.cloud:spring-cloud-aws-core',
    'org.springframework.cloud:spring-cloud-aws-autoconfigure',
    'org.springframework.boot:spring-boot-starter-actuator',
    'org.springframework.boot:spring-boot-starter-webflux',
    'org.springframework.boot:spring-boot-starter-jetty',
    'org.springframework.cloud:spring-cloud-starter-openfeign',
    'org.springframework.boot:spring-boot-starter-cache',
    'org.springframework.boot:spring-boot-starter-data-jpa',
    'org.springframework.boot:spring-boot-starter-batch',
    'org.springframework.boot:spring-boot-starter-jdbc',
    'io.micrometer:micrometer-registry-statsd',
    'ch.qos.logback.contrib:logback-json-classic:0.1.5',
    'ch.qos.logback.contrib:logback-jackson:0.1.5',
  )
  implementation('org.mapstruct:mapstruct:1.4.2.Final')
  annotationProcessor('org.mapstruct:mapstruct-processor:1.4.2.Final')

  runtimeOnly(
    'org.postgresql:postgresql:42.2.2',
    'org.liquibase:liquibase-core',
  )

  testImplementation(
    'com.fasterxml.jackson.module:jackson-module-jaxb-annotations',
    'com.google.guava:guava-testlib',
    'com.opentable.components:otj-pg-embedded:0.13.1',
    /*'io.rest-assured:spring-web-test-client:4.1.2',*/
    'org.awaitility:awaitility:3.1.6',
    'org.springframework.boot:spring-boot-starter-test',
    'org.springframework.batch:spring-batch-test',
    /*'org.springframework.cloud:spring-cloud-starter-contract-verifier',*/
    'org.springframework.cloud:spring-cloud-stream-test-support'
  )
  testImplementation('org.springframework.cloud:spring-cloud-starter-contract-stub-runner') {
    exclude group: 'org.springframework.boot', module: 'spring-boot-starter-web'
  }
  testImplementation('org.springframework.cloud:spring-cloud-starter-contract-verifier') {
    exclude group: 'org.springframework', module: 'spring-webmvc'
  }
  testImplementation('io.rest-assured:spring-web-test-client:4.1.2') {
    exclude group: 'org.springframework', module: 'spring-webmvc'
  }
  testImplementation('io.findify:s3mock_2.12:0.2.4')
  testImplementation("com.company.conv:common-component-test:${componentTestVersion}")
}

// force to run sonarqube also after integration test to publish coverage report
project.tasks["sonarqube"].dependsOn test
openApi {
  apiDocsUrl.set("http://localhost:9898/v3/api-docs")
  outputDir.set(file("$buildDir/docs"))
  outputFileName.set("swagger.json")
  waitTimeInSeconds.set(90)
}

it has started working by replacing the implementation of open-api from webmvc to web-flux

implementation('org.springdoc:springdoc-openapi-webflux-ui:1.5.11')
implementation('org.springdoc:springdoc-openapi-webflux-core:1.5.11')

when accessing the swagger-ui.html in console of browser I am getting this error

{"path":"/docs/v3/api-docs","error":"Internal Server Error","message":"Duplicate key class Parameter {\n    name: api-version\n    in: header\n    description: null\n    required: null\n    deprecated: null\n    allowEmptyValue: null\n    style: null\n    explode: null\n    allowReserved: null\n    schema: class StringSchema {\n        class Schema {\n            type: string\n            format: null\n            $ref: null\n            description: null\n            title: null\n            multipleOf: null\n            maximum: null\n            exclusiveMaximum: null\n            minimum: null\n            exclusiveMinimum: null\n            maxLength: null\n            minLength: null\n            pattern: null\n            maxItems: null\n            minItems: null\n            uniqueItems: null\n            maxProperties: null\n            minProperties: null\n            required: null\n            not: null\n            properties: null\n            additionalProperties: null\n            nullable: null\n            readOnly: null\n            writeOnly: null\n            example: null\n            externalDocs: null\n            deprecated: null\n            discriminator: null\n            xml: null\n        }\n    }\n    examples: null\n    example: null\n    content: null\n    $ref: null\n}","timestamp":"Thu Nov 04 23:33:47 PKT 2021","status":500}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM