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

Spring项目从4.2.3.RELEASE升级至6.0.4遇SqlRowSet编译错误求助

问题描述

将多模块旧Spring项目从4.2.3.RELEASE版本升级至6.0.4版本,已升级spring-bean、spring-context、spring-jdbc、spring-orm等所有Spring依赖,但构建项目时出现编译错误,提示无法访问spring-jdbc中的SqlRowSet。代码已正确导入目标类,且子模块的Maven依赖文件夹中能找到完整的org.springframework.jdbc.support.rowset.SqlRowSet包和类。

编译错误信息:

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Project-Name\src\main\java\com\rest\retest\entity\ads\Test.java:[6,46] error: cannot access SqlRowSet
[INFO] 1 error
[INFO] -------------------------------------------------------------

相关代码片段:

import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.jdbc.support.rowset.SqlRowSetMetaData;

public abstract class Iterator {

    protected SqlRowSet rowSet;

    public void setSqlRowSet(SqlRowSet rowSet) {
        this.rowSet = rowSet;

        SqlRowSetMetaData metaData = rowSet.getMetaData();

        String[] columnNames = metaData.getColumnNames();

        setIndexes(columnNames);
    }
}
解决建议
  • 检查spring-jdbc依赖范围
    确保子模块pom.xml中spring-jdbc的依赖范围为compile(默认值),避免设置为provided或test导致编译阶段无法访问类:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>6.0.4</version>
        <!-- 确认无scope配置或scope为compile -->
    </dependency>
    
  • 清理Maven缓存并强制更新依赖
    本地Maven仓库可能存在损坏或不完整的依赖文件,执行以下命令清理后重新构建:

    mvn clean install -U
    

    -U参数会强制Maven更新所有快照和依赖,确保获取完整的6.0.4版本spring-jdbc包。

  • 排查多模块依赖冲突
    父模块或其他依赖模块可能引入了旧版本的spring-jdbc,导致依赖冲突。执行命令查看依赖树:

    mvn dependency:tree -Dincludes=org.springframework:spring-jdbc
    

    如果输出中出现4.2.3.RELEASE版本,在子模块pom.xml中排除对应依赖的旧版本:

    <dependency>
        <!-- 引入旧spring-jdbc的依赖模块 -->
        <groupId>xxx</groupId>
        <artifactId>xxx-module</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    
  • 确认JDK版本兼容性
    Spring 6.0要求JDK 17及以上,若项目编译使用低于17的JDK,可能出现类访问性问题。检查pom.xml中的编译插件配置:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.11.0</version>
        <configuration>
            <source>17</source>
            <target>17</target>
        </configuration>
    </plugin>
    

    同时确认IDE的项目JDK配置为17及以上。

  • 验证类的实例化方式
    尝试通过JdbcTemplate的queryForRowSet方法直接获取SqlRowSet实例,验证是否能正常编译:

    SqlRowSet rowSet = jdbcTemplate.queryForRowSet("SELECT * FROM your_table");
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 11:25:34