2015-04-28 24 views
1

我有一個彈簧集成sftp流,我將其作爲子上下文加載到我的整個應用程序上下文中。這是基於dynamic ftp SI example。我的整合流程與其中的反應堆或流沒有任何關係。它是一個簡單的流程,將一個direct channel連接到sftp-outbound-gateway以將文件傳輸到sftp服務器。我甚至可以運行單元測試和流程工作正常(能夠傳輸文件),但是當我運行一個集成測試加載完整的父應用程序,然後用它加載的這個sftp流初始化子上下文時,它會拋出一個錯誤無法找到reactor/StringUtils類。彈簧集成xml文件錯誤出在反應器上StringUtils

其原因似乎是spring-integration-sftp將反應堆罐裝載爲瞬態,但是由於我的父應用程序已經在類路徑中加載了不同版本的反應堆,因此我從彈簧集成dep中排除了反應堆堆芯。如果我不排除彈簧整合的反應堆核心,那麼存在一些版本衝突,所以我想排除它。

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: 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)

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


更新添加我的反應器配置

@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(); 
     } 
    }; 
} 
} 

回答

0

搖籃目前不排除做傳遞依賴的依賴非常出色。

這不是spring-integration-sftp拉動反應堆,它是spring-integration-core

嘗試明確排除通過。

我們已經刪除了SI 4.2中的硬傳遞反應堆依賴關係(但它尚未發佈)。

春季隊已經創建了一個gradle plugin,可能會有所幫助。

+0

實際上它不僅僅是從彈簧一體化中排除反應堆。看來SI使用'reactor'的版本'1.1.4',其中'StringUtils'類在utils包中,並且在較新的'2.0.0.M2'版本的反應器中(其中大部分支持spring)都有StringUtils in 'reactor.core.support'包。 – adeelmahmood

+0

如果我讓反應堆1.1.4與彈簧一體化核心一起使用,那麼我會遇到這個錯誤。 '找不到名爲'shared'的Dispatcher,它必須存在於配置屬性中,或者通過編程方式通過#addDispatcher(shared,someDispatcher)註冊。爲什麼發生這種情況。任何想法 – adeelmahmood

+0

reactor2中的所有包/ maven座標已更改,以使它們能夠共存於類路徑中,所以我懷疑它僅僅是1.1.4的存在 - 您是否嘗試過[2.0.0.RELEASE](http:// projectreactor .IO /)? –