消息传递异常:sftp出站通道适配器中的org.springframework.Messaging.MessageDeliveryException
消息传递异常:org.springframework.Messaging.MessageDeliveryException:Dispatcher没有频道“org.springframework.web.context.WebApplicationContext:/.sftpChannel”的订户。;嵌套异常为org.springframework.integration.MessageDispatchingException:Dispatcher没有订阅服务器 我正在尝试将文件从本地发送到远程服务器 我的应用程序上下文如下消息传递异常:sftp出站通道适配器中的org.springframework.Messaging.MessageDeliveryException,spring,spring-integration,sftp,Spring,Spring Integration,Sftp,消息传递异常:org.springframework.Messaging.MessageDeliveryException:Dispatcher没有频道“org.springframework.web.context.WebApplicationContext:/.sftpChannel”的订户。;嵌套异常为org.springframework.integration.MessageDispatchingException:Dispatcher没有订阅服务器 我正在尝试将文件从本地发送到远程服
<bean id="startupBean" class="com.SchedulerImpl" init-method="run"/>
<bean id="applicationContextProvider" class="com.ApplicationContextProvider"></bean>
<bean id="sftpSessionFactory" class="org.springframework.integration.file.remote.session.CachingSessionFactory">
<constructor-arg ref="defaultSftpSessionFactory" />
</bean>
<bean id="defaultSftpSessionFactory" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
<property name="host" value="${destination.host}"/>
<property name="privateKey" value="${destination.privateKey}"/>
<property name="privateKeyPassphrase" value="${destination.privateKeyPassphrase}"/>
<property name="port" value="${destination.port}"/>
<property name="user" value="${destination.user}"/>
<property name="sessionConfig" ref="props"/>
</bean>
<util:properties id="props">
<prop key="PreferredAuthentications">publickey</prop>
</util:properties>
<int:channel id="sftpChannel"/>
<int-sftp:outbound-channel-adapter id="sftpOutboundAdapter"
session-factory="sftpSessionFactory"
channel="sftpChannel"
auto-startup ="false"
charset="UTF-8"
remote-directory="/destinationFolder/"
remote-file-separator="/">
</int-sftp:outbound-channel-adapter>
<int:publish-subscribe-channel id="contextRefreshEvents"/>
<int:outbound-channel-adapter channel="contextRefreshEvents"
expression="sftpOutboundAdapter.start()" />
公钥
因此,我在sftp类的代码中得到了与以下相同的applicationContext实例:
ApplicationContext context=appContext.getApplicationContext()
MessageChannel sftpChannel=(MessageChannel)context.getBean(“sftpChannel”)
和@Autowired private ApplicationContextProvider appContext;
在同一个sftp类中
还有另一个类ApplicationContextProvider,它实现ApplicationContextAware,帮助我获取当前的ApplicationContext
我不明白为什么找不到订户。
我已将自动启动设置为false。
获取当前SFTPchannelbean的正确方法是什么?它为我提供了相同的applicationContext实例
如果我执行appContext=new classpathxmlapplicationcontext(applicationcontext.xml)
我在startupBean中遇到错误,所以我不想这样做
现在我正在实现ApplicationContextAware,并且我得到了消息传递异常
谁能帮我一下吗
我使用的是spring 3,你已经分享了很多想法,最后你的问题变得一团糟 从另一边让我解释一下发生了什么 由于在
上有auto startup=“false”
,因此任何发送到sftpChannel
的操作都会导致该异常,直到您启动该适配器为止
从另一个角度看,我看到您这样做了,虽然我们不知道是谁发起了contextRefreshEvents
消息,但我们相信您是
这里还有一点,您没有向我们显示来自本地的文件。好的,我猜是
。它是可轮询的,并在应用程序启动后立即开始轮询本地主管。因此,这可能会导致Dispatcher没有订户,因为sftpOutboundAdapter
尚未启动
让我知道,如果我在推理上走错了方向,但你期待着不同的东西
更新
要以编程方式启动端点(或任何其他生命周期组件),您应该将其注入到您的服务中:
@Autowired
@Qualifier("sftpOutboundAdapter")
private Lifecycle sftpOutboundAdapter;
....
sftpOutboundAdapter.start();
你分享了很多你的想法,最后你的问题变得一团糟
从另一边让我解释一下发生了什么
由于在
上有auto startup=“false”
,因此任何发送到sftpChannel
的操作都会导致该异常,直到您启动该适配器为止
从另一个角度看,我看到您这样做了,虽然我们不知道是谁发起了contextRefreshEvents
消息,但我们相信您是
这里还有一点,您没有向我们显示来自本地的文件。好的,我猜是
。它是可轮询的,并在应用程序启动后立即开始轮询本地主管。因此,这可能会导致Dispatcher没有订户,因为sftpOutboundAdapter
尚未启动
让我知道,如果我在推理上走错了方向,但你期待着不同的东西
更新
要以编程方式启动端点(或任何其他生命周期组件),您应该将其注入到您的服务中:
@Autowired
@Qualifier("sftpOutboundAdapter")
private Lifecycle sftpOutboundAdapter;
....
sftpOutboundAdapter.start();
感谢您的回复,bt如果我没有内置applicationContext,如何从代码启动出站适配器?现在我得到错误:消息传递异常:org.springframework.MessagingException:;嵌套异常为org.springframework.messaging.MessaginException:无法获取池项目;嵌套异常为java.lang.IllegalStateException:未能创建SFTP会话是否意味着我需要执行-->@Autowired@Qualifier(“sftpSessionFactory”)专用生命周期sftpSessionFactory;和sftpSessionFactory.start();内部代码?感谢您的回复,bt如果我没有内部应用程序上下文,如何从代码启动出站适配器?现在我得到错误:消息异常:org.springframework.MessagingException:;嵌套异常为org.springframework.messaging.MessaginException:无法获取池项目;嵌套异常为java.lang.IllegalStateException:未能创建SFTP会话是否意味着我需要执行-->@Autowired@Qualifier(“sftpSessionFactory”)专用生命周期sftpSessionFactory;和sftpSessionFactory.start();内码?