You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3.2.3迁移后bootrun失败:已配-parameters仍遇Redis Bean冲突

问题

将Spring Boot从3.1.5版本迁移至3.2.3版本后,执行bootRun时启动失败,报错信息如下:

要求获取org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration对应的单个Bean,但发现存在7个。

系统给出操作建议Ensure that your compiler is configured to use the '-parameters' flag,但Gradle已配置-parameters编译参数,问题仍未解决。

提供的build.gradle代码:

buildscript {
    dependencies {
        classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.3")
        classpath("org.springframework.boot:spring-boot-gradle-plugin")
    }
}

plugins {
    id 'org.springframework.boot' version '3.2.3'
    id 'io.spring.dependency-management' version '1.0.14.RELEASE'
    id 'java'
    id 'org.sonarqube' version '4.3.1.3277'
    id 'jacoco'
    id 'eclipse'
    id 'idea'
}

repositories {
    mavenCentral()
}

ext {
    hibernateVersion = '6.2.5.Final'
    microserviceBaseName = 'consents'
    globalVersion = '1.0.0'
    deployDir = 'deploy/application/dist'
    buildType = 'SNAPSHOT'
    microserviceDesc = 'Consents Service'
}

bootJar {
    archiveBaseName = project.property('microserviceBaseName')
    archiveVersion = project.property('globalVersion') + '.' + project.property('buildType')
    destinationDirectory = file(project.property('deployDir'))
}

tasks.register('copyProperties', Copy) {
    from('src/main/resources/')
    into(project.property('deployDir'))
    include('application.properties')
}

tasks.withType(JavaCompile).configureEach {
    options.compilerArgs.add("-parameters")
    doFirst {
        println "Compiler arguments for compileJava task: $options.compilerArgs"
    }
}

processResources.finalizedBy copyProperties

sourceCompatibility = 17
targetCompatibility = 17

dependencyManagement {
    resolutionStrategy {
        cacheChangingModulesFor 0, 'seconds'
    }
}

dependencies {
    configurations.configureEach {
        exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
        exclude group: "org.yaml", module: "snakeyaml"
    }
    implementation 'co.elastic.apm:apm-agent-api:1.36.0'
    implementation 'co.elastic.apm:apm-agent-attach:1.36.0'
    implementation 'co.elastic.logging:log4j2-ecs-layout:1.5.0'
    implementation group: 'com.github.ulisesbocchio', name: 'jasypt-spring-boot-starter', version: '3.0.5'
    implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
    implementation group: 'com.google.code.gson', name: 'gson', version: '2.9.1'
    implementation('com.lmax:disruptor:4.0.0.RC1')
    implementation group: 'commons-codec', name: 'commons-codec', version: '1.15'
    implementation("in.novopay:infra-http-client")
    implementation("in.novopay:infra-cache")
    implementation("in.novopay:infra-jtf")
    implementation("in.novopay:infra-masterdata")
    implementation("in.novopay:infra-navigation")
    implementation("in.novopay:infra-notifications")
    implementation("in.novopay:infra-platform")
    implementation("in.novopay:infra-service-gateway")
    implementation("in.novopay:util-platform")
    implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
    implementation group: 'org.apache.commons', name: 'commons-text', version: '1.10.0'
    implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
    implementation 'org.flywaydb:flyway-core:5.2.0'
    implementation('org.junit.jupiter:junit-jupiter-api:5.9.2')
    implementation('org.junit.jupiter:junit-jupiter-engine:5.9.2')
    implementation('org.junit.platform:junit-platform-runner:1.9.2')
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-log4j2'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-test'
    implementation 'org.json:json:20231013'
    implementation group: 'org.owasp.antisamy', name: 'antisamy', version: '1.7.4'
    implementation 'org.apache.kafka:kafka-clients:3.6.1'
    implementation group: 'org.thymeleaf', name: 'thymeleaf-spring6', version: '3.1.1.RELEASE'

    testImplementation group: 'org.bouncycastle', name: 'bcprov-jdk18on', version: '1.77'
    testImplementation "org.powermock:powermock-module-junit4:2.0.7"
    testImplementation "org.powermock:powermock-module-junit4-rule:2.0.7"
    testImplementation "org.powermock:powermock-api-mockito2:2.0.7"
    testImplementation "org.powermock:powermock-classloading-xstream:2.0.9"
    testImplementation('org.mockito:mockito-core:4.11.0')
    testImplementation('org.mockito:mockito-junit-jupiter:4.11.0')
    testImplementation group:"org.mockito", name:"mockito-inline", version:"4.2.0"

    developmentOnly 'org.springframework.boot:spring-boot-devtools'

    runtimeOnly 'mysql:mysql-connector-java:8.0.31'
}

tasks.named('test') {
    useJUnitPlatform()
}

解决步骤

  • 排查依赖冲突:项目引入的in.novopay:infra-*系列依赖可能重复引入了Redis相关自动配置类,导致容器中出现多个RedisReactiveAutoConfiguration实例。执行以下命令分析依赖树:

    ./gradlew dependencyInsight --dependency org.springframework.boot:spring-boot-autoconfigure
    

    若发现多版本自动配置依赖或重复模块,通过exclude语法移除多余依赖。

  • 显式排除RedisReactive自动配置:如果项目不需要Reactive Redis功能,直接禁用该自动配置:

    • 启动类方式:
      @SpringBootApplication(exclude = RedisReactiveAutoConfiguration.class)
      public class ConsentsApplication {
          public static void main(String[] args) {
              SpringApplication.run(ConsentsApplication.class, args);
          }
      }
      
    • 配置文件方式(application.properties):
      spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration
      
  • 验证编译参数生效:虽然配置了-parameters,需确认编译后的类包含参数信息。执行以下命令检查任意编译后的class文件:

    javap -v -p build/classes/java/main/com/yourpackage/YourClass.class
    

    查看输出是否存在MethodParameters属性。同时确保bootRun依赖最新编译产物,可在build.gradle中添加:

    tasks.named('bootRun') {
        dependsOn compileJava
    }
    
  • 清理缓存并重建:清除旧编译产物和依赖缓存,避免旧版本类残留:

    ./gradlew clean build --refresh-dependencies
    
  • 检查自定义Redis配置:若项目有自定义Redis配置类,确认是否重复注册了Reactive Redis相关Bean(如ReactiveRedisConnectionFactory),调整配置避免与自动配置冲突。

内容的提问来源于stack exchange,提问作者lupin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 15:28:16