2014-03-03 99 views
2

我需要在弹簧初始化后立即加载一堆数据,只需要一次。 在我的计划中,我有与控制总线一起工作的服务激活器(发送消息来控制总线通道)。 创建初始化后发送这串数据的服务不起作用,这个96221-jdbc-inbound-channel-adapter-for-doing-only-a-single-query-at-runtime也不帮助 - 即时获取org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers。尝试了几种方法,包括BeanPostProcessor,MethodInvokingFactoryBean,但仍然有方法调用时尚未启动的感觉渠道。 任何方法来解决这个问题?初始化和弹簧集成通道

更新:ApplicationListener<ContextRefreshedEvent>作为魔法。 Thx咨询

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> 

回答

6

您太快发送数据。

执行ApplicationListener并在收到ContextRefreshedEvent时发送数据。

+0

谢谢,它的工作。没有意识到BeanPostProcessor在bean初始化之后工作,而不是在整个上下文之后 – ametiste

1

调度员没有订户

说,你有一些SubscribableChannel(如刚),其中没有任何端点从中接收消息,或端点没有启动(auto-startup="false") 。

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

+0

Gary Russel的建议为我工作,似乎没有它的一些订户丢失,但万一我错过了一些具体细节,我添加了配置,将欣赏任何信息 – ametiste

+0

不,一切都是正确。对不起,感到困惑。请记住我的评论:当你失去一些订阅时,这是一个典型的问题。 –