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

Spring Batch从3.x.x升级到4.x.x后出现Bean创建异常

Spring Batch 3.x升级4.x后StoredProcedureItemReader初始化异常解决

核心问题

异常的根本原因是**org.springframework.batch.core.resource.ListPreparedStatementSetter类在Spring Batch 4.x中已迁移到新包路径**,原包下的该类已被移除,导致类加载失败。

解决方案

1. 修正类的全限定名

Spring Batch 4.x中,ListPreparedStatementSetter的新包路径为:org.springframework.batch.item.database.support.ListPreparedStatementSetter。

需要在XML配置中,将所有引用该类的地方替换为新路径。示例修正后的配置:

<bean id="xxx" class="org.springframework.batch.item.database.StoredProcedureItemReader">
    <!-- 替换preparedStatementSetter的实现类路径 -->
    <property name="preparedStatementSetter">
        <bean class="org.springframework.batch.item.database.support.ListPreparedStatementSetter">
            <!-- 此处保留原有的参数配置 -->
        </bean>
    </property>
    <!-- 补充其他必要配置:如dataSource、procedureName等 -->
</bean>

2. 清理依赖冲突

检查项目依赖(Maven/Gradle),确保没有同时引入Spring Batch 3.x和4.x的依赖,避免类路径冲突。例如Maven中可通过dependencyManagement统一管理版本,排除旧版本依赖。

3. 注解配置场景适配

如果是使用Java注解配置,需修正import语句:

// 替换旧导入
// import org.springframework.batch.core.resource.ListPreparedStatementSetter;
import org.springframework.batch.item.database.support.ListPreparedStatementSetter;

原因说明

Spring Batch 4.x对框架内部的包结构做了重构,将数据库相关的辅助工具类统一归类到org.springframework.batch.item.database.support包下,原org.springframework.batch.core.resource包下的相关类已被迁移,这是升级后出现类找不到异常的直接原因。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 05:05:30