反应器StringUtils

时间:2015-04-28 20:55:55

标签: spring-integration project-reactor

我有一个spring integration sftp流程,我在整个应用程序上下文中作为子上下文加载。这基于dynamic ftp SI example。我的集成流程中没有任何关于反应堆或流的信息。它是一个简单的流程,其中一个direct channelsftp-outbound-gateway连接,以将文件传输到sftp服务器。我甚至可以运行单元测试并且流程工作正常(能够传输文件)但是当我运行加载完整父应用程序的集成测试然后在其中加载了这个sftp流来初始化子上下文时,它会抛出错误无法找到reactor / StringUtils类。

原因似乎是spring-integration-sftp将reactor jar加载为瞬态deps,但由于我的父应用程序已经在类路径中加载了不同版本的reactor,因此我从spring integration dep中排除了reactor-core。如果我不从弹簧集成中排除reactor-core,那么就会出现一些版本冲突,所以我想排除它。

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"
}

初始化SI流程

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

运行集成测试时的错误

  

org.springframework.beans.factory.BeanDefinitionStoreException:从类路径资源解析XML文档时出现意外异常[adapters / sftp.xml];嵌套异常是java.lang.NoClassDefFoundError:reactor / util / StringUtils       在org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:414)       在org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)       在org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)       在org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)

最后的SI流程

<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" />

更新以添加我的reactor配置

@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 个答案:

答案 0 :(得分:0)

Gradle目前在排除传递依赖关系的依赖性方面做得不好。

反应堆不是spring-integration-sftp,而是spring-integration-core

尝试明确排除那个。

我们已经删除了SI 4.2中的硬传递反应堆依赖性(但尚未发布)。

Spring团队创建了一个可能有用的gradle plugin