簡體   English   中英

消息異常:sftp出站通道適配器中的org.springframework.messaging.MessageDeliveryException

[英]Messaging exception: org.springframework.messaging.MessageDeliveryException in sftp outbound-channel-adapter

消息傳遞異常:org.springframework.messaging.MessageDeliveryException:調度程序沒有頻道“ org.springframework.web.context.WebApplicationContext:/。sftpChannel”的訂閱者。 嵌套的異常是org.springframework.integration.MessageDispatchingException:調度程序沒有訂閱者

我正在嘗試將文件從本地發送到遠程服務器。

我的應用程序上下文如下

 <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上下文= appContext.getApplicationContext();

MessageChannel sftpChannel =(MessageChannel)context.getBean(“ sftpChannel”);

和@Autowired私有ApplicationContextProvider appContext; 在相同的sftp類中。

還有一個實現ApplicationContextAware的類ApplicationContextProvider,可以幫助我獲取當前的ApplicaitonContext。

我不明白為什么我找不到訂戶。 我已經把auto-startup = false了。 什么是獲取當前sftpChannel bean的正確方法,它為我提供了applicationContext的相同實例。

如果我執行appContext = new classpathxmlapplicationcontext(applicationcontext.xml),則會在startupBean中出錯,所以我不想這樣做。

現在,我正在實現ApplicationContextAware,並且遇到了Messaging異常。

有人可以幫我嗎?

我正在使用Spring 3

您從腦海中分享了很多東西,最后您的問題變得一團糟。

從另一面讓我解釋發生了什么。

因為您在<int-sftp:outbound-channel-adapter>上具有auto-startup ="false" ,所以任何sendsftpChannel都會導致該異常,直到您啟動該適配器為止。

從另一面看,盡管您看不到誰發起了contextRefreshEvents消息,但我相信您是這樣做的,但是我們相信您是<int-event:inbound-channel-adapter>

還有一點,您不要向我們展示file from local 好的,我想這是<int-file:inbound-channel-adapter> 這是可輪詢的,並在應用程序啟動后立即開始輪詢本地控制器。 因此,這可能導致Dispatcher has no subscribers ,因為sftpOutboundAdapter尚未啟動。

讓我知道,如果我在推理中走錯了路,但您期望有所不同。

UPDATE

要以編程方式啟動端點(或任何其他Lifecycle組件),應將其inject到服務中:

@Autowired
@Qualifier("sftpOutboundAdapter")
private Lifecycle sftpOutboundAdapter;

....

sftpOutboundAdapter.start();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM