2016-05-23 68 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

所以我重现你的错误,并通过执行上面提到的步骤,每件事情都很好。您是否在添加了依赖关系后重新构建了应用程序? –