我正在尝试让Swagger在我的项目中工作,我正在跟踪这些医生,但是无论我尝试什么,我的应用程序都会立即崩溃,只有以下例外:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through method 'setContentNegotationStrategy' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'swaggerWebMvcConfigurer' defined in class path resource [org/springdoc/webmvc/ui/SwaggerConfig.class]: Unsatisfied dependency expressed through method 'swaggerWebMvcConfigurer' parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'indexPageTransformer' defined in class path resource [org/springdoc/webmvc/ui/SwaggerConfig.class]: Unsatisfied dependency expressed through method 'indexPageTransformer' parameter 3; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'swaggerWelcome' defined in class path resource [org/springdoc/webmvc/ui/SwaggerConfig.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springdoc.webmvc.ui.SwaggerWelcomeWebMvc] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@251a69d7]
我在Spring中使用Kotlin,这些是我的Gradle依赖关系:
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-jooq")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-configuration-processor")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-log4j2")
implementation("com.braintreepayments.gateway:braintree-java:3.14.0")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.1")
implementation("com.fasterxml.jackson.core:jackson-databind:2.13.2")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.2")
implementation("org.apache.logging.log4j:log4j-layout-template-json")
implementation("org.springdoc:springdoc-openapi-kotlin:1.6.6")
implementation("org.springdoc:springdoc-openapi-ui:1.6.6")
implementation("org.jooq:jooq-meta")
implementation("org.jooq:jooq-kotlin")
implementation("org.jooq:jooq-codegen")
implementation("org.jooq:jooq-codegen-maven")
implementation("org.jooq:jooq-meta-extensions")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.6.10")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10")
implementation("com.zaxxer:HikariCP:5.0.1")
implementation("com.github.ben-manes.caffeine:caffeine:3.0.5")
implementation("org.flywaydb:flyway-core:8.5.4")
implementation("org.postgresql:postgresql:42.3.3")
我在很多不同的组合中尝试过很多不同的包,但在启动时总是会抛出异常。
Gradle文件的插件部分:
plugins {
id("org.springframework.boot") version "3.0.0-SNAPSHOT"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
id("org.flywaydb.flyway") version "8.5.4"
id("nu.studer.jooq") version "7.1.1"
kotlin("jvm") version "1.6.20-RC"
kotlin("plugin.spring") version "1.6.20-RC"
}
发布于 2022-04-08 18:32:42
Spring 3将使用Jakarta,而Spring 2仍然使用Java。此移动包括Servlet从javax.servlet
到jakarta.servlet
的命名空间更改。您的应用程序失败了,因为Springdoc1.x试图从旧的命名空间加载类,但是Springdoc 3只使用新的命名空间。
Springdoc发布了一个与Jakarta一起工作的里程碑版本,以及Springdoc 3的里程碑版本:https://github.com/springdoc/springdoc-openapi/issues/1284
在Java应用程序中,您可以替换
implementation 'org.springdoc:springdoc-openapi-ui:1.6.6'
使用
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.0-M1'
这里还有一个官方的Maven示例:https://github.com/springdoc/springdoc-openapi-demos/tree/2.x/demo-spring-boot-3-webmvc
如果您只将启动器包含到Kotlin项目中,则
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.0-M1")
这似乎很好,并生成Swagger用户界面。但是,目前似乎还没有相应的springdoc-openapi-kotlin
里程碑版本。
https://stackoverflow.com/questions/71678911
复制相似问题