为什么应用程序反应式(Webflux)在迁移到SpringBoot 3.0.4后不运行。

huangapple go评论110阅读模式
英文:

Why app reactive(Webflux) don't runnig after migration to SpringBoot 3.0.4

问题

App在迁移到Spring Boot Starter WebFlux 3.0.3版本后,以及在3.0.4版本中启动时抛出异常。

启动日志如下:

org.springframework.context.ApplicationContextException: 无法启动响应式Web服务器 at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:84)
...
Caused by: org.springframework.beans.factory.BeanCreationException: 创建名为'undertowReactiveWebServerFactory'的bean时发生错误
...
Caused by: java.lang.NoSuchFieldError: DECODE_SLASH
...

我的gradle.build文件:

ext {
    mockServerVersion = '5.15.0'
    springBootVersion = '3.0.4'
    junitJupiterVersion = '5.9.2'
    projectreactorVersion = '3.5.3'
    reactorKotlinVersion = '1.2.1'
    junitJupiterVersion = '5.9.2'
}

dependencies {
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: springBootVersion
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version: springBootVersion
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-webflux', version: springBootVersion
    implementation group: 'io.micrometer', name: 'micrometer-tracing-bridge-brave', version: '1.0.2'
    implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlinVersion
    implementation group: 'io.projectreactor.kotlin', name: 'reactor-kotlin-extensions', version: reactorKotlinVersion
    implementation group: 'io.springfox', name: 'springfox-boot-starter', version: swaggerSpringfoxVersion
    implementation group: 'io.projectreactor', name: 'reactor-tools', version: projectreactorVersion
    ...
}

也许有人知道如何解决这个问题。在Spring Boot Starter WebFlux 3.0.2版本上它能正常工作。

英文:

App throws exception on startup after migrating to spring-boot-starter-webflux 3.0.3 in version 3.0.4 as well.

Logs with start:

yorg.springframework.context.ApplicationContextException: Unable to start reactive web server at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:84) ~[spring-boot-3.0.4.jar:3.0.4] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:578) ~[spring-context-6.0.6.jar:6.0.6] at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66) ~[spring-boot-3.0.4.jar:3.0.4] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[spring-boot-3.0.4.jar:3.0.4] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-3.0.4.jar:3.0.4] at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) ~[spring-boot-3.0.4.jar:3.0.4] at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:150) ~[spring-boot-3.0.4.jar:3.0.4] at pl.lhsystems.groupapp.service.profileinformation.ProfileInformationServiceApplication.main(ProfileInformationServiceApplication.java:29) ~[main/:na] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'undertowReactiveWebServerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryConfiguration$EmbeddedUndertow.class]: DECODE_SLASH at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:606) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:205) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.getWebServerFactory(ReactiveWebServerApplicationContext.java:121) ~[spring-boot-3.0.4.jar:3.0.4] at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.createWebServer(ReactiveWebServerApplicationContext.java:93) ~[spring-boot-3.0.4.jar:3.0.4] at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:81) ~[spring-boot-3.0.4.jar:3.0.4] ... 7 common frames omitted Caused by: java.lang.NoSuchFieldError: DECODE_SLASH at org.springframework.boot.autoconfigure.web.embedded.UndertowWebServerFactoryCustomizer.mapSlashProperties(UndertowWebServerFactoryCustomizer.java:121) ~[spring-boot-autoconfigure-3.0.4.jar:3.0.4] at org.springframework.boot.autoconfigure.web.embedded.UndertowWebServerFactoryCustomizer.mapUndertowProperties(UndertowWebServerFactoryCustomizer.java:105) ~[spring-boot-autoconfigure-3.0.4.jar:3.0.4] at org.springframework.boot.autoconfigure.web.embedded.UndertowWebServerFactoryCustomizer.customize(UndertowWebServerFactoryCustomizer.java:85) ~[spring-boot-autoconfigure-3.0.4.jar:3.0.4] at org.springframework.boot.autoconfigure.web.embedded.UndertowWebServerFactoryCustomizer.customize(UndertowWebServerFactoryCustomizer.java:59) ~[spring-boot-autoconfigure-3.0.4.jar:3.0.4] at

My gradle.build


ext {
    mockServerVersion = '5.15.0'
    springBootVersion = '3.0.4'
    junitJupiterVersion = '5.9.2'
    projectreactorVersion = '3.5.3'
    reactorKotlinVersion = '1.2.1'
    junitJupiterVersion = '5.9.2'
}

dependencies {

    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: springBootVersion
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version: springBootVersion
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-webflux', version: springBootVersion
    implementation group: 'io.micrometer', name: 'micrometer-tracing-bridge-brave', version: '1.0.2'
    implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlinVersion
    implementation group: 'io.projectreactor.kotlin', name: 'reactor-kotlin-extensions', version: reactorKotlinVersion
    implementation group: 'io.springfox', name: 'springfox-boot-starter', version: swaggerSpringfoxVersion
    implementation group: 'io.projectreactor', name: 'reactor-tools', version: projectreactorVersion

    testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion
    testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: junitJupiterVersion
    testImplementation group: 'org.mock-server', name: 'mockserver-spring-test-listener', version: mockServerVersion
    testImplementation group: 'io.mockk', name: 'mockk', version: mockkVersion
    testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junitJupiterVersion
    testImplementation group: 'io.projectreactor', name: 'reactor-test', version: projectreactorVersion
    testImplementation group: 'org.awaitility', name: 'awaitility', version: awaitilityVersion
}

Maybe someone knows how to solve this problem. On spring-boot-starter-webflux 3.0.2 it worked

答案1

得分: 2

如果您查看堆栈跟踪,您将遇到以下内容:

Caused by: java.lang.NoSuchFieldError: DECODE_SLASH

这种类型的错误通常是因为您正在混合使用错误的依赖项。查看您的Gradle构建片段,您似乎正在努力解决Spring Boot依赖关系管理的问题。

使用以下方式整理您的依赖项:

  1. org.springframework.boot 依赖项中移除 version
  2. io.projectreactor 依赖项中移除 version
  3. 移除 junit-jupiter-engine 依赖项,因为它包含在 spring-boot-starter-test 中。
  4. ext 块中移除版本。
ext {
    mockServerVersion = '5.15.0'
}

dependencies {

    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-webflux'
    implementation group: 'io.micrometer', name: 'micrometer-tracing-bridge-brave'
    implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect'
    implementation group: 'io.projectreactor.kotlin', name: 'reactor-kotlin-extensions'
    implementation group: 'io.springfox', name: 'springfox-boot-starter', version: swaggerSpringfoxVersion
    implementation group: 'io.projectreactor', name: 'reactor-tools'

    testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'
    testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params'
    testImplementation group: 'org.mock-server', name: 'mockserver-spring-test-listener', version: mockServerVersion
    testImplementation group: 'io.mockk', name: 'mockk', version: mockkVersion
    testImplementation group: 'io.projectreactor', name: 'reactor-test'     
    testImplementation group: 'org.awaitility', name: 'awaitility', version: awaitilityVersion
}

现在唯一可能存在问题的是 springfox-boot-starter 依赖项,因为它已经超过2年,可能不适用于Spring Boot 3。

英文:

If you read the stacktrace you will encounter the following:

Caused by: java.lang.NoSuchFieldError: DECODE_SLASH

Those kinds of errors generally come from the fact that you are mixing wrong dependencies. Looking at the snippet of your Gradle build you are trying very hard to work around the Spring Boot dependency management.

Cleanup your dependencies with the following

  1. Remove the version from the org.springframework.boot dependencies
  2. Remove the version from the io.projectreactor dependencies
  3. Remove the junit-jupiter-engine dependency, included in spring-boot-starter-test
  4. Remove the versions from the ext block.
ext {
    mockServerVersion = '5.15.0'
}

dependencies {

    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-webflux'
    implementation group: 'io.micrometer', name: 'micrometer-tracing-bridge-brave'
    implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect'
    implementation group: 'io.projectreactor.kotlin', name: 'reactor-kotlin-extensions'
    implementation group: 'io.springfox', name: 'springfox-boot-starter', version: swaggerSpringfoxVersion
    implementation group: 'io.projectreactor', name: 'reactor-tools'

    testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'
    testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params'
    testImplementation group: 'org.mock-server', name: 'mockserver-spring-test-listener', version: mockServerVersion
    testImplementation group: 'io.mockk', name: 'mockk', version: mockkVersion
    testImplementation group: 'io.projectreactor', name: 'reactor-test'     
    testImplementation group: 'org.awaitility', name: 'awaitility', version: awaitilityVersion
}

Now the only thing left that could be an issue is the springfox-boot-starter dependency, as that is over 2 years old that will reference not Spring Boot 3.

huangapple
  • 本文由 发表于 2023年3月7日 18:24:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75660726.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定