Spring integration xml file errors out on reactor StringUtils

和自甴很熟 提交于 2019-12-11 07:27:15

问题


I have a spring integration sftp flow which I load as a child context within my overall application context. This is based on the dynamic ftp SI example. My integration flow has nothing about reactor or streams in it. Its a simple flow with one direct channel connected with a sftp-outbound-gateway to transfer files to a sftp server. I can even run units tests and the flow work fine (is able to transfer files) but when I run an integration test which loads the full parent application and then initializes the child context with this sftp flow loaded in it, it throws an error for not being able to find reactor/StringUtils class.

The reason for that seems to be that spring-integration-sftp loads reactor jars as transient deps but since my parent application already has a different version of reactor loaded in the classpath I excluded the reactor-core from spring integration dep. If I dont exclude the reactor-core from spring-integration then there are some version conflicts so I would like to exclude it.

reactorVersion = 2.0.0.M2

compile("io.projectreactor:reactor-core:$reactorVersion")
compile "io.projectreactor.spring:reactor-spring-context:$reactorVersion"

compile("org.springframework.integration:spring-integration-sftp") {
    exclude module: "reactor-core"
}

Initializing the SI flow

context = new ClassPathXmlApplicationContext(new String[] { "classpath:adapters/"
                + sink.getConfigurationFile() }, false);
        setEnvironment(context, sink);
        context.setParent(parentContext);
        context.refresh();
        context.registerShutdownHook();

The error when i ran the integration test

org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [adapters/sftp.xml]; nested exception is java.lang.NoClassDefFoundError: reactor/util/StringUtils at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:414) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)

Finally the SI flow

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-sftp="http://www.springframework.org/schema/integration/sftp"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.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
    http://www.springframework.org/schema/integration/sftp http://www.springframework.org/schema/integration/sftp/spring-integration-sftp.xsd">

<import resource="common.xml" />

<bean id="sftpSessionFactory"
    class="org.springframework.integration.file.remote.session.CachingSessionFactory">
    <constructor-arg ref="defaultSftpSessionFactory" />
</bean>

<bean id="defaultSftpSessionFactory"
    class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
    <property name="host" value="${sink.host}" />
    <property name="port" value="22" />
    <property name="privateKey" value="${sink.private.key}" />
    <property name="privateKeyPassphrase" value="${sink.private.key.phrase}" />
    <property name="user" value="${sink.user}" />
    <property name="password" value="${sink.pass}" />
</bean>

<int:channel id="input" />

<int-sftp:outbound-channel-adapter
    auto-startup="true" session-factory="sftpSessionFactory" channel="input"
    remote-directory="${sink.path}" remote-filename-generator-expression="headers['remote_file_name']">
    <int-sftp:request-handler-advice-chain>
        <bean
            class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
            <property name="onSuccessExpression" value="payload" />
            <property name="successChannel" ref="successChannel" />
            <property name="onFailureExpression" value="payload" />
            <property name="failureChannel" ref="failureChannel" />
            <property name="trapException" value="true" />
        </bean>
    </int-sftp:request-handler-advice-chain>
</int-sftp:outbound-channel-adapter>

<int:channel id="successChannel" />
<int:service-activator input-channel="successChannel"
    ref="completionHandler" method="handle" />

<int:channel id="failureChannel" />
<int:service-activator input-channel="failureChannel"
    ref="failureHandler" method="handle" />


Updating to add my reactor configuration

@Configuration
@EnableReactor
public class ReactorConfiguration {

static {
    Environment.initializeIfEmpty().assignErrorJournal();
}

@Bean
public EventBus eventBus() {
    return EventBus.config().env(Environment.get()).dispatcher(Environment.SHARED).get();
}

@Bean
public IdGenerator randomUUIDGenerator() {
    return new IdGenerator() {
        @Override
        public UUID generateId() {
            return UUIDUtils.random();
        }
    };
}
}

回答1:


Gradle currently doesn't do a great job excluding dependencies of transitive dependencies.

It's not spring-integration-sftp that pulls in reactor, it's spring-integration-core.

Try explicitly excluding via that.

We have removed the hard transitive reactor dependency in SI 4.2 (but it's not released yet).

The spring team has created a gradle plugin that might help.



来源:https://stackoverflow.com/questions/29929766/spring-integration-xml-file-errors-out-on-reactor-stringutils

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!