Frühling-FTP - Integration
, Was ich zu tun versuche :
Iam versucht, transfer-Datei aus C:\maven zu C:\shaileshftp mit spring ftp .
FTP-server verwendet - FileZillaServer.Host ist localhost.
Wir haben eine einzige Maschine zum testen der gesamten Funktionalität.
Problem-und Fehler-log -
SCHWER: Alle versuche, es zu liefern-Nachricht an MessageHandlers ist fehlgeschlagen. Mehrere Ursachen:
Fehler in message-handler - [org.springframework.- integration.ftp.gateway.FtpOutboundGateway#0]
Fehlerbehandlung Meldung für die Datei [c:\shaileshftp\b.txt -> b.txt]
verursachen.org.springframework.- integration.MessageHandlingException: Fehler in message-handler - [org.springframework.- integration.ftp.gateway.FtpOutboundGateway
Verursacht durch: java.lang.Classcastexception-Fehler: java.io.Datei kann nicht gewirkt werden, um java.lang.String
Spring configuration code:
-------------------------
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-stream="http://www.springframework.org/schema/integration/stream"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int-file="http://www.springframework.org/schema/integration/file"
xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp"
xsi:schemaLocation="http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp-2.2.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file-2.2.xsd
http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream-2.2.xsd
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">
<!-- Step1 :Adding FTP Namespace -->
<!-- Step2 : FPT session Factory configuration -->
<bean id="ftpSessionFactory"
class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="localhost" />
<property name="port" value="21" />
<property name="username" value="shailesh" />
<property name="password" value="Passw0rd" />
<property name="clientMode" value="0" />
<property name="fileType" value="2" />
<property name="bufferSize" value="100000" />
</bean>
<int:channel id="ftpChannel" />
<int-ftp:inbound-channel-adapter id="ftpInbound"
cache-sessions="false" channel="ftpChannel" session-factory="ftpSessionFactory"
charset="UTF-8" auto-create-local-directory="true"
delete-remote-files="true" filename-pattern="*.*" remote-directory="C:/maven"
remote-file-separator="/" local-directory="c:/shaileshftp">
<int:poller fixed-rate="1000" />
</int-ftp:inbound-channel-adapter>
<int-ftp:outbound-gateway id="gateway1"
session-factory="ftpSessionFactory" request-channel="ftpChannel"
command="ls" command-options="-1" expression="payload" reply-channel="ftpChannel" />
<int-ftp:outbound-channel-adapter id="ftpOutbound"
channel="ftpChannel" session-factory="ftpSessionFactory" charset="UTF-8"
remote-file-separator="/" auto-create-directory="true"
remote-directory-expression="headers['remote_dir']"
temporary-remote-directory-expression="headers['temp_remote_dir']" />
Java-Code
package com.mq.springintegration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class TestMqSpringIntegration {
public static void main(String[] args) {
try {
ApplicationContext ctx = new FileSystemXmlApplicationContext(
"src/res/applicationcontext.xml");
} catch (Exception e) {
e.printStackTrace();
}
}
}
- Sie müssen Ihren code und Sie die volle Konsole-Fehler ,sonst werde es so Aussehen wie ein viel zu vage.
- Danke, ich habe die komplette Konfiguration und den code.
- Es ist wirklich schwer zu sehen, wie der code, den Sie geschrieben hat nichts zu tun mit Ihrer Frage. Auch, warum tun Sie müssen sogar verwenden Sie ftp, um eine Datei zu kopieren lokal? Und wo in deinem code ist, dass die Anforderung Kopie schicken???
- Ich denke, dass die copy-Funktionalität automatisiert in das spring-framework. Ich habe nur eine Maschine zum testen der Funktionalität, so iam-Tests mit einer einzigen Maschine (local machine) und ftp.
Du musst angemeldet sein, um einen Kommentar abzugeben.
Konnte ich nicht wirklich bekommen Ihren code so, ich entschied mich für ein einfaches Beispiel basierend auf garyrussell 's repository
Hier sind die folgenden Quellen.
pom.xml
applicationContext.xml - Beachten Sie ausfüllen müssen in Ihrer Verbindung details
Und eine Beispiel-java-Klasse, die eine Nachricht sendet, bis zum Frühjahr Fragen zum upload einer test-Datei.
Hoffe, es funktioniert für Sie