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

使用OpenRewrite迁移Spring Boot 1.5.x至2.7.x时遇NoSuchMethodError的解决方法

OpenRewrite迁移Spring Boot 1.5.x到2.7.x时NoSuchMethodError错误解决方法

问题场景

使用OpenRewrite Maven插件将Spring Boot 1.5.x迁移至2.7.x,插件配置如下:

<plugin>
    <groupId>org.openrewrite.maven</groupId>
    <artifactId>rewrite-maven-plugin</artifactId>
    <version>4.44.0</version>
    <configuration>
        <activeRecipes>
            <recipe>org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_7</recipe>
        </activeRecipes>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.openrewrite.recipe</groupId>
            <artifactId>rewrite-spring</artifactId>
            <version>4.34.0</version>
        </dependency>
    </dependencies>
</plugin>

执行mvn rewrite:run时触发错误:

Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:4.44.0:dryRun failed: java.lang.NoSuchMethodError: 'void org.openrewrite.java.search.UsesType.<init>(java.lang.String)'

解决方法

该错误由rewrite-maven-plugin与rewrite-spring版本不兼容导致,需确保两者版本匹配,具体操作:

  • 调整插件和依赖版本至兼容组合,例如:
    将rewrite-maven-plugin升级到4.45.0,rewrite-spring升级到4.35.0,修改后的配置如下:
<plugin>
    <groupId>org.openrewrite.maven</groupId>
    <artifactId>rewrite-maven-plugin</artifactId>
    <version>4.45.0</version>
    <configuration>
        <activeRecipes>
            <recipe>org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_7</recipe>
        </activeRecipes>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.openrewrite.recipe</groupId>
            <artifactId>rewrite-spring</artifactId>
            <version>4.35.0</version>
        </dependency>
    </dependencies>
</plugin>
  • 清理并更新Maven依赖,执行命令:
mvn clean install -U
  • 重新运行迁移命令:
mvn rewrite:run

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 18:23:10