Custom LineMapper could not be registered from xml configuration when using spring batch and spring boot 2.2.5

Viewed 255

Version using:

  • Spring boot 2.2.5
  • Spring batch core 4.x

There is only one following bean in the spring-batch.xml file:

<bean id="lineMapper" primary="true" class="com.batch.ContextSavingLineMapper" scope="step">
        <property name="lineTokenizer">
            <bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
                <!-- This is to accept lines with incorrect number of tokens -->
                <property name="strict" value="false"/>
                <!-- Expected CSV column names -->
                <property name="names" value="#{jobParameters['columnNames']}" />
            </bean>
        </property>
        <property name="fieldSetMapper">
            <bean class="com.batch.DetectorRegistrationFieldSetMapper" />
        </property>
    </bean>

Class ContextSavingLineMapper is extended as below:

public class ContextSavingLineMapper<T> extends DefaultLineMapper<T> implements StepExecutionListener {

Message error:


Description:

The bean 'lineMapper', defined in BeanDefinition defined in class path resource [spring-batch.xml], could not be registered. A bean with that name has already been defined in class path resource [spring-batch.xml] and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

Note: I don't want to use spring.main.allow-bean-definition-overriding=true.

1 Answers
Related