gpt4 book ai didi

spring - 使用 spring batch 和 spring boot 2.2.5 时无法从 xml 配置中注册 Custom LineMapper

转载 作者:行者123 更新时间:2023-12-04 10:15:38 25 4
gpt4 key购买 nike

版本使用:

  • Spring Boot 2.2.5
  • Spring 批核 4.x

  • spring-batch.xml 文件中只有一个如下 bean:
    <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>

    类 ContextSavingLineMapper 扩展如下:
    public class ContextSavingLineMapper<T> extends DefaultLineMapper<T> implements StepExecutionListener {

    消息错误:

    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


    注意:我不想使用 spring.main.allow-bean-definition-overriding=true .

    最佳答案

    您遇到了这个 Unresolved 问题:https://github.com/spring-projects/spring-batch/issues/1050 .

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



    不幸的是,在上述问题得到解决之前,这是唯一的解决方法。

    关于spring - 使用 spring batch 和 spring boot 2.2.5 时无法从 xml 配置中注册 Custom LineMapper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61076101/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com