UnsatisfiedDependencyException 在设置 Spring Integration SFTP 出站网关时发生

huangapple go评论76阅读模式
英文:

UnsatisfiedDependencyException when setting up a Spring Integration SFTP outbound gateway

问题

以下是您提供的内容的翻译:

我正在尝试使用Spring Integration 5.3.2设置一个SFTP出站网关,但我真的无法理解哪里出了问题。

这是我的网关和会话工厂定义:

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

然而,在应用程序上下文初始化时,我收到以下异常:

org.springframework.beans.factory.UnsatisfiedDependencyException: 在类路径资源[config/integration/applicationContext-integration-sftp.xml]中定义的名为'org.springframework.integration.sftp.gateway.SftpOutboundGateway#0'的bean创建失败:通过构造函数参数0表达的不满足的依赖关系:无法将类型为[org.springframework.integration.sftp.session.SftpRemoteFileTemplate]的参数值转换为所需的类型[org.springframework.integration.file.remote.session.SessionFactory]:无法将类型为'org.springframework.integration.sftp.session.SftpRemoteFileTemplate'的值转换为所需的类型'org.springframework.integration.file.remote.session.SessionFactory';嵌套异常是java.lang.IllegalStateException: 无法将类型为'org.springframework.integration.sftp.session.SftpRemoteFileTemplate'的值转换为所需的类型'org.springframework.integration.file.remote.session.SessionFactory':找不到匹配的编辑器或转换策略
	...

我在俄语页面中找到了完全相同的问题:
https://fooobar.com/questions/16868233/sftp-spring-integration-channel-between-two-ec2-instance

这里有Artem Bilan的回答,我使用了谷歌翻译,但是我无法理解该答案的要点。我的意思是,在这里我只有一个网关和一个会话工厂。我还尝试过移除包装的CachingSessionFactory,将DefaultSftpSessionFactory直接连接到网关,但是仍然出现相同的异常。

我做错了什么?

英文:

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:

&lt;int-sftp:outbound-gateway
  id=&quot;myGateway&quot;
  request-channel=&quot;inputChannel&quot;
  reply-channel=&quot;outputChannel&quot;
  session-factory=&quot;mySessionFactory&quot;
  remote-directory=&quot;${sftp.base-path}&quot;
  command=&quot;put&quot; /&gt;

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

However I get this exception on application context initialisation:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name &#39;org.springframework.integration.sftp.gateway.SftpOutboundGateway#0&#39; 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 &#39;org.springframework.integration.sftp.session.SftpRemoteFileTemplate&#39; to required type &#39;org.springframework.integration.file.remote.session.SessionFactory&#39;; nested exception is java.lang.IllegalStateException: Cannot convert value of type &#39;org.springframework.integration.sftp.session.SftpRemoteFileTemplate&#39; to required type &#39;org.springframework.integration.file.remote.session.SessionFactory&#39;: 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?

答案1

得分: 1

原来这是一个错误。expression 属性必须在出站网关定义中指定,即使您希望在其他Spring Integration网关/适配器中使用默认值,即消息有效载荷;因此它变成了:

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

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

英文:

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, i.e. the message payload; so it becomes:

&lt;int-sftp:outbound-gateway
  id=&quot;myGateway&quot;
  request-channel=&quot;inputChannel&quot;
  reply-channel=&quot;outputChannel&quot;
  session-factory=&quot;mySessionFactory&quot;
  remote-directory=&quot;${sftp.base-path}&quot;
  command=&quot;put&quot;
  expression=&quot;payload&quot; /&gt;

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

huangapple
  • 本文由 发表于 2020年10月2日 01:10:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/64160194.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定