简体   繁体   English

设置 Spring Integration SFTP 出站网关时出现 UnsatisfiedDependencyException

[英]UnsatisfiedDependencyException when setting up a Spring Integration SFTP outbound gateway

I'm trying to set up a SFTP outbound gateway with Spring Integration 5.3.2, but I really can't understand what is wrong.我正在尝试使用 Spring Integration 5.3.2 设置 SFTP 出站网关,但我真的不明白出了什么问题。

Here is my gateway and session factory definition:这是我的网关和会话工厂定义:

<int-sftp:outbound-gateway
  id="myGateway"
  request-channel="inputChannel"
  reply-channel="outputChannel"
  session-factory="mySessionFactory"
  remote-directory="${sftp.base-path}"
  command="put" />

<bean id="mySessionFactory"
  class="org.springframework.integration.file.remote.session.CachingSessionFactory">
    <constructor-arg>
      <bean class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
        <property name="host" value="${sftp.host}" />
        <property name="port" value="${sftp.port}" />
        <property name="user" value="${sftp.username}" />
        <property name="password" value="${sftp.password}" />
        <property name="knownHostsResource" value="classpath:/config/integration/sftp_host" />
        <property name="timeout" value="${sftp.timeout}" />
      </bean>
    </constructor-arg>
    <constructor-arg value="3" />
    <property name="sessionWaitTimeout" value="120000" />
    <property name="testSession" value="true" />
</bean>

However I get this exception on application context initialisation:但是我在应用程序上下文初始化时遇到了这个异常:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.integration.sftp.gateway.SftpOutboundGateway#0' defined in class path resource [config/integration/applicationContext-integration-sftp.xml]: Unsatisfied dependency expressed through constructor parameter 0: Could not convert argument value of type [org.springframework.integration.sftp.session.SftpRemoteFileTemplate] to required type [org.springframework.integration.file.remote.session.SessionFactory]: Failed to convert value of type 'org.springframework.integration.sftp.session.SftpRemoteFileTemplate' to required type 'org.springframework.integration.file.remote.session.SessionFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'org.springframework.integration.sftp.session.SftpRemoteFileTemplate' to required type 'org.springframework.integration.file.remote.session.SessionFactory': no matching editors or conversion strategy found
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:765) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:227) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1203) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]

I found the following page in Russian, having the exact same problem: https://fooobar.com/questions/16868233/sftp-spring-integration-channel-between-two-ec2-instance我在俄语中找到了以下页面,有完全相同的问题: https : //fooobar.com/questions/16868233/sftp-spring-integration-channel-between-two-ec2-instance

There's a reply by Artem Bilan, I used Google Translator but I can't get the point of that answer. Artem Bilan 有一个回复,我使用了谷歌翻译,但我无法理解这个答案的要点。 I mean, here I have just one gateway and one session factory.我的意思是,这里我只有一个网关和一个会话工厂。 I also tried to remove the wrapping CachingSessionFactory and wire the DefaultSftpSessionFactory directly into the gateway, but it fails with the same exception.我还尝试删除包装 CachingSessionFactory 并将 DefaultSftpSessionFactory 直接连接到网关,但它因相同的异常而失败。

What am I doing wrong?我究竟做错了什么?

Turned out this is a bug.原来这是一个错误。 The expression attribute must be specified on the outbound gateway definition, even if you want to use what is the default in other Spring Integration gateways/adapters, ie the message payload;必须在出站网关定义中指定expression属性,即使您想使用其他 Spring Integration 网关/适配器中的默认值,即消息负载; so it becomes:所以它变成:

<int-sftp:outbound-gateway
  id="myGateway"
  request-channel="inputChannel"
  reply-channel="outputChannel"
  session-factory="mySessionFactory"
  remote-directory="${sftp.base-path}"
  command="put"
  expression="payload" />

I opened: https://github.com/spring-projects/spring-integration/issues/3395我打开: https : //github.com/spring-projects/spring-integration/issues/3395

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM