2016-05-23 63 views
2

我想創建使用駱駝春將文件從一個位置移動到另一個位置的組件。駱駝春:沒有找到與組件方案:sftp

它對於FTP工作正常,但在嘗試使用SFTP時出現錯誤。

錯誤是(SFTP URI:SFTP:// IP地址:端口/ CamelTesting用戶名= testftp &密碼= testftp):從類路徑資源[testApplicationContext.xml] 異常螺紋 加載XML bean定義「main」org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:來自類路徑資源[processorApplicationContext.xml]的XML文檔中的第25行無效;嵌套異常是org.xml.sax.SAXParseException; lineNumber:25; columnNumber:76;實體「密碼」的引用必須以';'結尾分隔符。

錯誤是(SFTP URI(&安培):SFTP:// IP地址:端口/ CamelTesting用戶名= testftp &密碼= testftp): 異常在線程 「主」 org.apache.camel.RuntimeCamelException :to [sftp:// IP Address:Port/CamelTesting?username = testftp & password = testftp] < < < in route:Route(route1):org.apache.camel.FailedToCreateRouteException:無法創建路由route1: [[從[file:D:/ Test/in]] - > [To [sftp:/ IP Address:Port ...因爲無法解析端點:sftp:// IP Address:Port/CamelTesting?password = testftp & username = testftp由於:找不到與組件相關的組件:sftp

依存關係是:

<dependencies> 
    <dependency> 
     <groupId>org.apache.camel</groupId> 
     <artifactId>camel-core</artifactId> 
     <version>2.15.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>4.1.5.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.camel</groupId> 
     <artifactId>camel-spring</artifactId> 
     <version>2.15.1</version> 
    </dependency> 
</dependencies> 

testApplicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.springframework.org/schema/beans  
http://www.springframework.org/schema/beans/spring-beans.xsd 
http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd">  
<camelContext xmlns="http://camel.apache.org/schema/spring"> 
    <!--FTP Working fine--> 
    <!--route> 
     <from uri="file:D:/Test/in" />       
     <to uri="file:D:/Test/out" /> 
    </route--> 

    <!--SFTP--> 
    <route> 
     <from uri="file:D:/Test/in" />   
     <to uri="sftp://<IP Address:Port>/CamelTesting?username=testftp&password=testftp"/> 
    </route> 
</camelContext> 

測試類:

import org.apache.camel.CamelContext; 
import org.apache.camel.spring.SpringCamelContext; 
import org.springframework.context.ConfigurableApplicationContext; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 

public class testSFTP { 
public static final void main(String[] args) throws Exception { 
    ConfigurableApplicationContext appContext = new ClassPathXmlApplicationContext("testApplicationContext.xml"); 
    CamelContext camelContext = SpringCamelContext.springCamelContext(appContext, false); 
    try { 
     camelContext.start(); 
     Thread.sleep(3000); 
    }catch(Exception e){ 
     e.printStackTrace(); 
    } 
    finally { 
     camelContext.stop(); 
     appContext.close(); 
    } 
    } 
} 

有人可以幫我解決問題。

在XML使用 &amp;

回答

5

爲&

<route> 
    <from uri="file:D:/Test/in" />   
    <to uri="sftp://<IP Address:Port>/CamelTesting?username=testftp&amp;password=testftp"/> 
</route> 

爲secord錯誤:

您需要駱駝FTP添加到類路徑。只需將它作爲依賴添加到pom.xml。

<dependency> 
     <groupId>org.apache.camel</groupId> 
     <artifactId>camel-ftp</artifactId> 
     <version>2.15.1</version> 
    </dependency> 

希望這有助於。

+0

感謝Hisham重播。我曾試過&和&。請檢查兩個錯誤的。 –

+0

添加駱駝ftp依賴,直到它給出相同的錯誤消息。 –

+0

所以我重現你的錯誤,並通過執行上面提到的步驟,每件事情都很好。您是否在添加了依賴關係後重新構建了應用程序? –