英文:
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:
<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?
答案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:
<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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论