Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6622945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:28:19+00:00 2026-05-25T21:28:19+00:00

I am working on setting a spring batch job that does the conventional READ

  • 0

I am working on setting a spring batch job that does the conventional READ > PROCESS > WRITE operation. However, I am trying to implement a listener which would capture records that are conisdered invalid during the PROCESS phase and write it out to an error log file.

My listener class uses an instance of FlatFileItemWriter to write the data. However, spring-batch is not instantiating the writer instance properly.

My listener class looks like this:

    public class DTOProcessorListener extends SkipListenerSupport<AttributeReportGenerationDTO, AttributeValue> {

    private static final Logger LOGGER = LoggerFactory.getLogger(DTOProcessorListener.class);

    private FlatFileItemWriter<AttributeReportGenerationDTO> flatFileItemWriter;

    @Override
    public void onSkipInProcess(AttributeReportGenerationDTO item, Throwable t) {

        try {
            LOGGER.error("Record not processed for attribute value with ID : " + item.getAttributeValueId());
            List<AttributeReportGenerationDTO> list = new ArrayList<AttributeReportGenerationDTO>();
            list.add(item);
            flatFileItemWriter.write(list);
        } catch (Exception e) {
            LOGGER.error("Unable to write to the error output file", e);
        }
    }

    /**
     * @param flatFileItemWriter
     *            the flatFileItemWriter to set
     */
    public void setFlatFileItemWriter(FlatFileItemWriter<AttributeReportGenerationDTO> flatFileItemWriter) {

        this.flatFileItemWriter = flatFileItemWriter;
    }

}

and my job configuration XML looks like this:

<bean id="skipListener" class="something.DTOProcessorListener" scope="step">
        <property name="flatFileItemWriter">
            <bean id="errorItemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
                <property name="resource" value="file:#{jobParameters['error.filename']}" />
                <property name="appendAllowed" value="true" />
                <property name="lineAggregator">
                    <bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
                        <property name="fieldExtractor">
                            <bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
                                <property name="names"
                                    value="productTypeId, productTypeName, productId, productName, skuId, skuName, attributeValueId, attributeName, attributeValue, attributeType, nonEditableValueCheckSum, editableValueCheckSum" />
                            </bean>
                        </property>
                    </bean>
                </property>
                <property name="headerCallback">
                    <bean class="something.CsvHeaderImplementation">
                        <property name="headerString"
                            value="Product Type ID,Product Type,Product ID,Product Name,Sku ID,Sku Name,Attribute Value ID,Attribute Name,Attribute Value,Attribute Type,Check Sum 1,Check Sum 2" />
                    </bean>
                </property>
            </bean>
        </property>
    </bean>

I get the error

org.springframework.batch.item.WriterNotOpenException: Writer must be open before it can be written to

I am unable to set a stream entry in the job config as the bean for FlatFileItemWriter is internally specified (for the listener). If I create abean outside of the listener and refer to it, its returning a proxy instance of the FlatFileItemWriterClass.

Has anyone successfully wired up a writer to a flat file in the listener?

Thanks for the help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:28:20+00:00Added an answer on May 25, 2026 at 9:28 pm

    Well why don’t you use the writer as a normal bean ? You could register it as a stream and to get around the step proxy you could use the PropertPlaceholderConfigurer

    i created a working example under my github repo, but i think spring batch could need an improvement here, it should be easier to implement error-item logging

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working with MyBatis-Spring integration framework and that's what I read from docs:
I am setting scrollTop and scrollLeft for a div that I am working with.
I am just working on a basic webapp that implements spring + hibernate entitymanager
I'm working through Peter Mularien's Spring Security 3, and am having a problem setting
I am working on setting up a Drupal based website and wanted to replace
I'm working on setting up NHibernate for a project and I have a few
I'm rather new to Powershell and am working on setting up my profile.ps1 file.
In Visual Source Safe 6.0, you could reset a working folder by setting it
I am working in flex and I am just setting a variable to false.
When working with tables in Oracle, how do you know when you are setting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.