Spring Integration从5.2.x升级到5.3问题

问题描述 投票:1回答:1

我想将Spring引导版本从2.2.7.RELEASE升级到2.3.0.RELEASE,我也在使用带有XML配置的Spring集成文件(请参见下文)。启动我的应用程序时,将引发NullPointerException。调试完该问题后,根本原因是创建了Bean file:inbound-channel-adapter。有趣的是,只有导致这种问题的这种类型的bean引起了,而其他所有原因都没有。有人遇到过类似的问题吗?任何人都可以帮助将XML转换为Java配置样式吗?预先感谢。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:int="http://www.springframework.org/schema/integration"
       xmlns:task="http://www.springframework.org/schema/task"
       xmlns:file="http://www.springframework.org/schema/integration/file"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
       http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
       http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">


    <bean id="compositeFilter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
        <constructor-arg>
            <list>
                <ref bean="ignoreHiddenFileListFilter"/>
                <ref bean="acceptOnceFileListFilter"/>
                <ref bean="extensionFileFilter"/>
            </list>
        </constructor-arg>
    </bean>

    <!-- upload folder listener  -->
    <file:inbound-channel-adapter id="uploadFilesScanner" directory="${integration.upload-folder}" filter="compositeFilter">
        <int:poller fixed-rate="${integration.poller-rate:10000}"/>
    </file:inbound-channel-adapter>

    <file:outbound-gateway request-channel="uploadFilesScanner" reply-channel="batchFilesScanner" directory="${integration.directory}" delete-source-files="true"/>

    <!-- 1) Scan for files -->
    <file:inbound-channel-adapter id="batchFilesScanner" directory="${integration.directory}" filter="compositeFilter">
        <int:poller fixed-rate="5000"/>
    </file:inbound-channel-adapter>

    <!-- 2) move the file to processing -->
    <file:outbound-gateway request-channel="batchFilesScanner" reply-channel="batchFilesProcessing" directory="${integration.processing-folder}" delete-source-files="true"/>

    <!-- 3) transform csv file -->
    <int:service-activator input-channel="batchFilesProcessing" output-channel="batchFilesTran" ref="batchTransformerTask" method="execute"/>

    <!-- 4) move the file to archive folder -->
    <file:outbound-gateway request-channel="batchFilesTran" reply-channel="batchFilesArchive" directory="${integration.archive-folder}" delete-source-files="true"/>

    <int:service-activator input-channel="batchFilesArchive" ref="cleanupHelper" method="execute"/>

    <!-- Transformer task channel configuration -->
    <task:executor id="batchFilesTranTaskExecutor" pool-size="1" rejection-policy="CALLER_RUNS" queue-capacity="1"/>
    <int:channel id="batchFilesTran">
        <int:dispatcher load-balancer="round-robin" task-executor="batchFilesTranTaskExecutor" failover="false"/>
    </int:channel>

    <int:service-activator input-channel="errorChannel" ref="intErrorHandler" method="execute"/>

</beans>

NullPointerException

Caused by:
        java.lang.NullPointerException
            at org.springframework.integration.support.utils.IntegrationUtils.obtainComponentName(IntegrationUtils.java:205)
            at org.springframework.integration.graph.IntegrationGraphServer$NodeFactory.sourceNode(IntegrationGraphServer.java:399)
            at org.springframework.integration.graph.IntegrationGraphServer.lambda$pollingAdapters$1(IntegrationGraphServer.java:216)
            at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
            at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
            at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
            at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
            at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
            at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
            at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
            at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
            at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
            at org.springframework.integration.graph.IntegrationGraphServer.pollingAdapters(IntegrationGraphServer.java:221)
            at org.springframework.integration.graph.IntegrationGraphServer.buildGraph(IntegrationGraphServer.java:184)
            at org.springframework.integration.graph.IntegrationGraphServer.onApplicationEvent(IntegrationGraphServer.java:116)
            at org.springframework.integration.graph.IntegrationGraphServer.onApplicationEvent(IntegrationGraphServer.java:67)
            at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
            at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
            at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
            at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:403)
            at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:360)
            at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:897)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553)
            at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
            at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
            at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
            at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
            at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120)
            at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
            at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
            ... 88 more

spring-boot spring-integration spring-integration-file
1个回答
0
投票

问题已确认。 FileReadingMessageSourceFactoryBean不会将beanName填充到它生成的FileReadingMessageSource中。

您的配置太大,无法立即在此处进行转换。考虑遵循文档:https://docs.spring.io/spring-integration/docs/current/reference/html/overview.html#programming-tips

<file:inbound-channel-adapter>的Java和注释配置类似如下:

@Bean
@InboundChannelAdapter
public FileReadingMessageSource fileReadingMessageSource() {

...
}

在此处查看更多信息:https://docs.spring.io/spring-integration/docs/current/reference/html/configuration.html#annotations

对于Java DSL,只需要一个IntegrationFlows.from(MessageSource)工厂并遵循其构建者的名称即可:

https://docs.spring.io/spring-integration/docs/current/reference/html/dsl.html#java-dsl-inbound-adapters

© www.soinside.com 2019 - 2024. All rights reserved.