FlatFileItemWriter无法创建新文件或更新现有文件

[SpringBatch的新功能]我试图使用Spring Boot创建一个作业,该作业从MongoDB中读取名称,转换为小写字母,然后输出为CSV文件。我的阅读器和处理器正在工作,但作家没有。

我的代码如下。

处理器文件


package bbye;


import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.springframework.batch.item.ItemProcessor;

import org.springframework.stereotype.Component;


import hello.Person;


@Component

public class PersonDocProcessor implements ItemProcessor<Person, Person> {


    private static final Logger log = LoggerFactory.getLogger(PersonDocProcessor.class);


    @Override

    public Person process(final Person person) throws Exception {

        final String firstName = person.getFirstName().toLowerCase();

        final String lastName = person.getLastName().toLowerCase();


        final Person transformedPerson = new Person(firstName, lastName);


        log.info("Converting (" + person + ") into (" + transformedPerson + ")");


        return transformedPerson;

    }

}

听众


package bbye;


import org.springframework.batch.core.JobExecution;

import org.springframework.batch.core.JobExecutionListener;

import org.springframework.stereotype.Component;


@Component

public class FileUploadNotificationListener implements JobExecutionListener {


    @Override

    public void beforeJob(JobExecution jobExecution) {

        System.out.println("===== listening for job - mongoReader - fileWriter ====");


    }


    @Override

    public void afterJob(JobExecution jobExecution) {

        System.out.println("==== file write job completed =====");


    }

}


阿波罗的战车
浏览 253回答 2
2回答

holdtom

我认为我们应该使用FileSystemResource而不是ClassPathResource。您能否尝试让我们知道。

冉冉说

事实证明,编写者的工作正常,但是我看的是错误的文件。使用ClassPathResource时,将在target / classes目录下创建并更新文件。但是,我正在查看src / main / resources目录下的PersonExtracted.csv&nbsp;,该目录从未更新。如果我指定FileSystemResource,那么将在指定位置创建并更新文件。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java