Spring 将@StepScope添加到ItemWriter会导致ClassCastException:$Proxy57无法强制转换为ItemStream

Spring 将@StepScope添加到ItemWriter会导致ClassCastException:$Proxy57无法强制转换为ItemStream,spring,spring-batch,Spring,Spring Batch,我在spring批处理作业中定义了一个步骤。请注意,我只包括我认为相关的内容 @Bean public Step readStgDbAndExportMasterListStep( @Qualifier("queryStagingDbReader") ItemReader<MasterList> queryStagingDbReader, @Qualifier("masterListOutputProcessor") ItemProcessor<

我在spring批处理作业中定义了一个步骤。请注意,我只包括我认为相关的内容

@Bean
public Step readStgDbAndExportMasterListStep(
        @Qualifier("queryStagingDbReader") ItemReader<MasterList> queryStagingDbReader,
        @Qualifier("masterListOutputProcessor") ItemProcessor<MasterList,MasterList> masterListOutputProcessor,
        @Qualifier("masterListFileWriter") ItemWriter<MasterList> masterListFileWriter,
        @Qualifier("divisionMasterListFileWriter") ItemWriter<MasterList> divisionMasterListFileWriter,
        @Qualifier("stepListener") CustomStepExecutionListener stepListener) {

    return  commonJobConfig.stepBuilderFactory
                .get("readStgDbAndExportMasterListStep")
                .<MasterList,MasterList>chunk(commonJobConfig.chunkSize)
                .reader(queryStagingDbReader)
                .processor(masterListOutputProcessor)
                .writer(masterListFileWriter)
                .stream((ItemStream) divisionMasterListFileWriter)
                .listener(stepListener)
                .build();               
}
将@stepScope添加到writer似乎破坏了步骤定义的.stream部分

有人能帮我解决这个问题吗

我不确定,但也许这和什么有关?在找到jira链接后,我也尝试了下面的链接,但它没有改变任何事情

@Scope(value = "step", proxyMode = ScopedProxyMode.TARGET_CLASS)

谢谢

将方法的返回类型更改为
FlatFileItemWriter
。java配置查看方法的返回类型以确定代理什么,在您的示例中,它只是
ItemWriter
,它不会检查运行时对象,因为此时没有对象。谢谢。这解决了我的问题。但也提高了我对java配置在spring中如何工作的理解。谢谢。这个评论应该是可以接受的答案。我在混合@Component和XML配置时也有同样的问题。用
scope=“step”
在XML配置中定义bean对我来说很有用。不知道为什么。也许@MichaelMinella知道?
Error creating bean with name 'readStgDbAndExportMasterListStep' defined in ExportMasterListCsvJobConfig:  java.lang.ClassCastException: com.sun.proxy.$Proxy57 cannot be cast to org.springframework.batch.item.ItemStream
@Scope(value = "step", proxyMode = ScopedProxyMode.TARGET_CLASS)