初始化和弹簧集成通道

时间:2014-03-03 15:14:46

标签: java spring-integration

我需要在Spring初始化后立即加载一堆数据,只需一次。 在我的方案中,我有服务激活器,它与控制总线一起工作(发送消息到控制总线通道)。 创建在初始化后发送这一堆数据的服务没有帮助,这96221-jdbc-inbound-channel-adapter-for-doing-only-a-single-query-at-runtime也没有帮助 - 我得到了org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers。尝试了几种方法,包括BeanPostProcessorMethodInvokingFactoryBean,但仍然感觉信道在方法调用时尚未启动。 有什么方法可以解决这个问题吗?

upd:ApplicationListener<ContextRefreshedEvent>充当魔力。请求建议

UPD2:
下面问题部分的配置。诀窍在于 cbManager ,它将消息发送到controlBus,调用 providerManager bean的方法。 ("@providerManager.add(headers.providerConfig)")。 适用于http-inbound部分,但 jdbcPoller 任务在初始化时也是如此。 ApplicationListener解决了我的问题,但如果有什么我不知道的或其他选择,我很高兴知道

    <int:control-bus input-channel="controlBusMainChannel"/>

    <int:channel id="controlBusMainChannel" />
    <int:channel id="cbRequests" />
    <int:channel id="cbReplies" />
    <int:channel id="postRequests" />

    <bean id="cbManager" class ="com.dph.hlss.bus.ViaBusProviderManager">
        <constructor-arg name="channel" ref="controlBusMainChannel" />
    </bean>

     <int-http:inbound-gateway id="cbPostController"
        request-channel="cbRequests"
        reply-channel="cbReplies"
        path="/controlbus/providers" 
        request-payload-type="com.dph.hlss.bus.providermanager.model.ProviderAddDTO"
        supported-methods="POST"
        payload-expression="body"   
    >
        <int-http:header name="requestId" expression="T(java.util.UUID).randomUUID().toString()"/>
    </int-http:inbound-gateway>

    <int:service-activator input-channel="cbRequests" ref="cbInbound"/> 

    <int:gateway id="cbInbound" default-request-channel="cbInbRequests"  error-channel="cbErrorHandleMessages" />

    <int:transformer input-channel="cbErrorHandleMessages" output-channel="cbReplies" ref="errorTransformer" method="transform"/>

    <int:payload-type-router input-channel="cbInbRequests" >
        <int:mapping type="com.dph.hlss.bus.providermanager.model.ProviderAddDTO" channel="postRequests"/>
    </int:payload-type-router>

    <int:service-activator id="addProvider" input-channel="postRequests" output-channel="cbReplies" ref="cbManager" method="add" />

    <bean id="providerManager" class="com.dph.hlss.bus.ProviderCommandManagment" >
        <property name="providerManager" ref="searchProviderManager"/>
        <property name="factory" ref="abstractProvidersFactory" />

    </bean>

    <bean id="jdbcPoller" class="com.dph.hlss.bus.JDBCPoller" >
        <property name="accepter" ref="cbManager" />
    </bean>

    <bean class="com.dph.interfaces.spring.SpringBeanLauncher">
        <property name="launchableBean" ref="jdbcPoller" />
        <property name="contextId" value="/search-facade" />
        <property name="rootContextId" value="org.springframework.web.context.WebApplicationContext:" />
    </bean>

2 个答案:

答案 0 :(得分:6)

您过早发送数据。

实施ApplicationListener并在收到ContextRefreshedEvent时发送数据。

答案 1 :(得分:1)

  

Dispatcher没有订阅者

说你有一些SubscribableChannel(例如just),它没有任何端点来接收来自它的消息,或者该端点没有启动(auto-startup="false")。

显示你的,配置,请了解发生了什么。