Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java spring批处理,Itemwriterlistener未注册,因此未调用,为什么?_Java_Spring_Spring Boot_Annotations_Spring Batch - Fatal编程技术网

Java spring批处理,Itemwriterlistener未注册,因此未调用,为什么?

Java spring批处理,Itemwriterlistener未注册,因此未调用,为什么?,java,spring,spring-boot,annotations,spring-batch,Java,Spring,Spring Boot,Annotations,Spring Batch,我正在尝试将steplistener(ItemwriterListener)添加到注释批处理配置中,没有任何错误,但不会被调用为什么??它以旧的xml配置样式工作,但在使用注释时不起作用。 代码如下。读卡器和处理器被省略了 @ImportResource({ "classpath*:transform-delegator-job.xml", "classpath:config/context.xml" }) @SpringBootApplication public class Spri

我正在尝试将steplistener(ItemwriterListener)添加到注释批处理配置中,没有任何错误,但不会被调用为什么??它以旧的xml配置样式工作,但在使用注释时不起作用。 代码如下。读卡器和处理器被省略了

    @ImportResource({ "classpath*:transform-delegator-job.xml", "classpath:config/context.xml" })
@SpringBootApplication
public class SpringBootTransformDelegatorJobApplication {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private static final List<String> OVERRIDDEN_BY_EXPRESSION_LIST = null;
    private static final String OVERRIDDEN_BY_EXPRESSION_STRING = null;

    @Autowired
    private JobBuilderFactory jobBuilders;

    @Autowired
    private StepBuilderFactory stepBuilders;

    @Bean
    public JobBuilderFactory jobBuilderFactory(JobRepository jobRepository) {
    return new JobBuilderFactory(jobRepository);
    }

    @Bean
    public StepBuilderFactory stepBuilderFactory(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
    return new StepBuilderFactory(jobRepository, transactionManager);
    }

    @Bean
    @StepScope
    public ItemWriter<Record> fileItemWriter(@Value("#{jobParameters['tews.customer.url']}") String url, @Value("#{jobParameters['tews.customer.user']}") String user,
        @Value("#{jobParameters['tews.customer.pwd']}") String pwd) {
    FileItemWriter writer = new FileItemWriter();
    TewsClient client = TewsClientFactory.getInstance(user, pwd, url);
    writer.setTewsClient(client);
    writer.setHrObjectDao(hrObjectDao(OVERRIDDEN_BY_EXPRESSION_STRING, OVERRIDDEN_BY_EXPRESSION_STRING, OVERRIDDEN_BY_EXPRESSION_STRING, OVERRIDDEN_BY_EXPRESSION_STRING));

    return writer;
    }

    @Bean
    @StepScope
    public FlatFileItemReader<FieldSet> reader(@Value("#{jobParameters['input.file.delimitter']}") String delimitter, @Value("#{jobParameters['input.file.names']}") String filePath,
        @Value("#{jobParameters['input.file.encoding']}") String encoding) throws Exception {
    FlatFileItemReader<FieldSet> reader = new FlatFileItemReader<FieldSet>();

    PathResource pathResources = new PathResource(Paths.get(filePath));
    Scanner scanner = new Scanner(pathResources.getInputStream());
    String names = scanner.nextLine();
    scanner.close();

    DelimitedLineTokenizer delimitedLineTokenizer = new DelimitedLineTokenizer();
    delimitedLineTokenizer.setNames(names.split(delimitter));
    delimitedLineTokenizer.setDelimiter(delimitter);
    DefaultLineMapper<FieldSet> defaultLineMapper = new DefaultLineMapper<FieldSet>();
    defaultLineMapper.setLineTokenizer(delimitedLineTokenizer);
    defaultLineMapper.setFieldSetMapper(new PassThroughFieldSetMapper());
    reader.setLineMapper(defaultLineMapper);
    reader.setLinesToSkip(1);
    reader.setEncoding(encoding);
    reader.afterPropertiesSet();
    return reader;
    }

    @Bean
    @StepScope
    public ItemProcessor<FieldSet, Record> csvFeedValidateProcessor(@Value("#{jobParameters['input.file.imeconfig.path']}") String imeConfigPath) {

    FieldCollectionConfiguration fieldCollectionConfiguration = null;
    try {
        XMLUnmarshaller<FieldcollectionType> unmarshaller = new XMLUnmarshaller<FieldcollectionType>();
        fieldCollectionConfiguration = fieldCollectionBeanToModelTransform().transform(unmarshaller.unmarshallByFile(FieldcollectionType.class, new File(imeConfigPath)));
    } catch (UnmarshallingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    CsvFeedTransformProcessor csvFeedTransformProcessor = new CsvFeedTransformProcessor();
    csvFeedTransformProcessor.setFieldCollectionConfiguration(fieldCollectionConfiguration);
    return csvFeedTransformProcessor;
    }

    @Bean
    @StepScope
    public HRObjectDao hrObjectDao(@Value("#{jobParameters['ldap.customer.url']}") String url, @Value("#{jobParameters['ldap.customer.user']}") String user,
        @Value("#{jobParameters['ldap.customer.pwd']}") String pwd, @Value("#{jobParameters['ldap.customer.bcontext']}") String bcontext) {

    return new HRObjectDaoImpl(bcontext, url, user, pwd);
    }

    @Bean
    public Transform<FieldcollectionType, FieldCollectionConfiguration> fieldCollectionBeanToModelTransform() {
    return new FieldCollectionBeanToModelTransform();
    }

    @Bean
    @StepScope
    public MultiResourceItemReader<FieldSet> multiResourceReader(@Value("#{jobParameters['input.file.paths'].split(',')}") List<String> filePathList) throws Exception {
    MultiResourceItemReader<FieldSet> multiResourceItemReader = new MultiResourceItemReader<FieldSet>();
    multiResourceItemReader.setDelegate(reader(OVERRIDDEN_BY_EXPRESSION_STRING, OVERRIDDEN_BY_EXPRESSION_STRING, OVERRIDDEN_BY_EXPRESSION_STRING));
    PathResource[] pathResources = new PathResource[filePathList.size()];

    for (int i = 0; i < filePathList.size(); i++) {
        pathResources[i] = new PathResource(Paths.get(filePathList.get(i)));
    }
    multiResourceItemReader.setResources(pathResources);

    return multiResourceItemReader;
    }

    @Bean
    public JobParametersIncrementer jobParametersIncrementer() {
    return new RunIdIncrementer();
    }

    @Bean
    public Job job() throws Exception {
    return jobBuilders.get("feedfiletransformer-delegate-job").listener(feedJobExecutionListener()).start(step1()).incrementer(jobParametersIncrementer()).build();
    }

    @Bean
    public Step step1() throws Exception {

    return stepBuilders.get("step1").listener(fileItemWriteListener(OVERRIDDEN_BY_EXPRESSION_STRING, OVERRIDDEN_BY_EXPRESSION_STRING, OVERRIDDEN_BY_EXPRESSION_STRING)).<FieldSet, Record>chunk(1)
        .reader(multiResourceReader(OVERRIDDEN_BY_EXPRESSION_LIST)).processor(csvFeedValidateProcessor(OVERRIDDEN_BY_EXPRESSION_STRING))
        .writer(fileItemWriter(OVERRIDDEN_BY_EXPRESSION_STRING, OVERRIDDEN_BY_EXPRESSION_STRING, OVERRIDDEN_BY_EXPRESSION_STRING)).build();
    }

    @Bean
    public FeedFileHandler feedFileHandler() {
    return new FeedFileHandlerImpl();
    }

    @Bean
    @StepScope
    public ItemWriteListener<Path> fileItemWriteListener(@Value("#{jobParameters['feeddumpDirPath']}") String feeddumpDirPath,
        @Value("#{jobParameters['processedOkDirPath']}") String processedOkDirPath, @Value("#{jobParameters['processedFailedDirPath']}") String processedFailedDirPath) {

    FileItemWriteListener fileItemWriteListener = new FileItemWriteListener();
    fileItemWriteListener.setFeedProcessedFailedDirectory(processedFailedDirPath);
    fileItemWriteListener.setFeedProcessedOkDirectory(processedOkDirPath);
    fileItemWriteListener.setFeeddumpDirPath(feeddumpDirPath);
    fileItemWriteListener.setFeedFileHandler(feedFileHandler());
    fileItemWriteListener.setRetryLimit(0);

    return fileItemWriteListener;
    }

    @Bean
    public JobExecutionListener feedJobExecutionListener() {
    return new FeedJobExecutionListener();
    }

    public static void main(String[] args) throws Exception {
    SpringApplication.run(SpringBootTransformDelegatorJobApplication.class, args);
    }
}
@ImportResource({“classpath*:transform delegator job.xml”,“classpath:config/context.xml})
@SpringBoot应用程序
公共类SpringBootTransformDelegatorJobApplication{
私有最终记录器Logger=LoggerFactory.getLogger(this.getClass());
私有静态最终列表被\u表达式\u覆盖\u List=null;
私有静态最终字符串被\u表达式\u String=null覆盖;
@自动连线
私人建筑工人工厂建筑工人;
@自动连线
私人StepBuilder工厂stepBuilders;
@豆子
公共JobBuilderFactory JobBuilderFactory(JobRepository JobRepository){
返回新的JobBuilderFactory(jobRepository);
}
@豆子
公共StepBuilderFactory StepBuilderFactory(JobRepository JobRepository,PlatformTransactionManager transactionManager){
返回新的StepBuilderFactory(jobRepository、transactionManager);
}
@豆子
@步进镜
public ItemWriter fileItemWriter(@Value(“#{jobParameters['tews.customer.url']}”)字符串url,@Value(“#{jobParameters['tews.customer.user']}”)字符串user,
@值(“#{jobParameters['tews.customer.pwd']}”)字符串pwd){
FileItemWriter writer=新建FileItemWriter();
TewsClient client=TewsClientFactory.getInstance(用户、pwd、url);
writer.settwsclient(客户端);
writer.setHrObjectDao(hrObjectDao(被表达式字符串覆盖,被表达式字符串覆盖,被表达式字符串覆盖,被表达式字符串覆盖,被表达式字符串覆盖));
返回作者;
}
@豆子
@步进镜
公共FlatFileItemReader读取器(@Value(“#{jobParameters['input.file.Delimiter']}”)字符串定界器,@Value(@Value(“#{jobParameters['input.file.names']}”)字符串文件路径,
@值(“#{jobParameters['input.file.encoding']}”)字符串编码)引发异常{
FlatFileItemReader=新的FlatFileItemReader();
PathResource pathResources=新的PathResource(path.get(filePath));
Scanner Scanner=新的扫描仪(pathResources.getInputStream());
字符串名称=scanner.nextLine();
scanner.close();
DelimitedLineTokenizer DelimitedLineTokenizer=新的DelimitedLineTokenizer();
delimitedLineTokenizer.setNames(names.split(delimiter));
delimitedLineTokenizer.setDelimiter(定界符);
DefaultLineMapper DefaultLineMapper=新的DefaultLineMapper();
defaultLineMapper.setLineTokenizer(delimitedLineTokenizer);
defaultLineMapper.setFieldSetMapper(新的PassThroughFieldSetMapper());
reader.setLineMapper(defaultLineMapper);
reader.setLinesToSkip(1);
设置编码(编码);
reader.afterPropertiesSet();
返回读取器;
}
@豆子
@步进镜
public ItemProcessor csvFeedValidateProcessor(@Value(“#{jobParameters['input.file.imeconfig.path']}”)字符串imeConfigPath){
FieldCollectionConfiguration FieldCollectionConfiguration=null;
试一试{
XMLUnmarshaller unmarshaller=新的XMLUnmarshaller();
fieldCollectionConfiguration=FieldCollectionBeantModelTransform().transform(unmarshaller.unmarshallByFile(FieldcollectionType.class,新文件(imeConfigPath));
}捕获(解组异常e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
CsvFeedTransformProcessor CsvFeedTransformProcessor=新CsvFeedTransformProcessor();
csvFeedTransformProcessor.setFieldCollectionConfiguration(fieldCollectionConfiguration);
返回csvFeedTransformProcessor;
}
@豆子
@步进镜
公共HRObjectDao HRObjectDao(@Value(“#{jobParameters['ldap.customer.url']}”)字符串url,@Value(“#{jobParameters['ldap.customer.user']}”)字符串user,
@Value(“#{jobParameters['ldap.customer.pwd']}”)字符串pwd,@Value(#{jobParameters['ldap.customer.bcontext']})字符串bcontext){
返回新的HRObjectDaoImpl(b上下文、url、用户、pwd);
}
@豆子
公共转换字段集合BeantModelTransform(){
返回新的FieldCollectionBeantModelTransform();
}
@豆子
@步进镜
公共MultiResourceItemReader multiResourceReader(@Value(“#{jobParameters['input.file.path'].split(',')}”)列表文件路径列表)引发异常{
MultiResourceItemReader MultiResourceItemReader=新的MultiResourceItemReader();
setDelegate(读卡器(由表达式字符串覆盖,由表达式字符串覆盖,由表达式字符串覆盖,由表达式字符串覆盖));
PathResource[]pathResources=新的PathResource[filePathList.size()];
对于(int i=0;i    @Bean
@StepScope
public ItemWriteListener fileItemWriteListener(@Value("#{jobParameters['feeddumpDirPath']}") String feeddumpDirPath, @Value("#{jobParameters['processedOkDirPath']}") String processedOkDirPath,
    @Value("#{jobParameters['processedFailedDirPath']}") String processedFailedDirPath) {

FileItemWriteListener fileItemWriteListener = new FileItemWriteListener();
fileItemWriteListener.setFeedProcessedFailedDirectory(processedFailedDirPath);
fileItemWriteListener.setFeedProcessedOkDirectory(processedOkDirPath);
fileItemWriteListener.setFeeddumpDirPath(feeddumpDirPath);
fileItemWriteListener.setFeedFileHandler(feedFileHandler());
fileItemWriteListener.setRetryLimit(0);

return fileItemWriteListener;
}


[public ItemWriteListener fileItemWriteListener]

was set like this before 
 public ItemWriter<Record> fileItemWriter.


so only works without the type parameter
@Bean
@StepScope
public ItemWriteListener fileItemWriteListener(@Value("#{jobParameters['feeddumpDirPath']}") String feeddumpDirPath, @Value("#{jobParameters['processedOkDirPath']}") String processedOkDirPath,
    @Value("#{jobParameters['processedFailedDirPath']}") String processedFailedDirPath) {
@Bean
@StepScope
public FileItemWriteListener fileItemWriteListener(@Value("#{jobParameters['feeddumpDirPath']}") String feeddumpDirPath, @Value("#{jobParameters['processedOkDirPath']}") String processedOkDirPath,
    @Value("#{jobParameters['processedFailedDirPath']}") String processedFailedDirPath) {