简体   繁体   中英

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.

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

There's a reply by Artem Bilan, I used Google Translator but I can't get the point of that answer. 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.

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; 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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