Spring批次:NotSerializableException

Spring batch: NotSerializableException

我有 pojo class 被 Spring 批处理作业使用。

public class DataItem{
    String key;
    CellType type; //Enum
    String name;

    private XSSFCell cell; //org.apache.poi.xssf.usermodel.XSSFCell


   //getters setters omitted
}

当我尝试 运行 批处理作业时出现以下异常:

java.lang.IllegalArgumentException: Failed to serialize object of type: class org.springframework.batch.core.JobExecution
    at org.springframework.util.SerializationUtils.serialize(SerializationUtils.java:49)
    at org.springframework.batch.core.repository.dao.MapJobExecutionDao.copy(MapJobExecutionDao.java:50)
    at org.springframework.batch.core.repository.dao.MapJobExecutionDao.updateJobExecution(MapJobExecutionDao.java:104)
    at org.springframework.batch.core.repository.support.SimpleJobRepository.update(SimpleJobRepository.java:162)
    at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:351)
    at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:135)
    at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
    at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)
    at  com.excelreader.AppMain.run(AppMain.java:35)
    at  com.excelreader.AppMain.main(AppMain.java:16)
Caused by: java.io.NotSerializableException: com.excelreader.pojo.DataItem

DataItem 并且其中的所有内容都必须实现 Serializable 接口。这就是您收到此异常的原因。