how to resolve Dispatcher has no subscribers for channel?

不羁岁月 提交于 2019-12-25 07:58:41

问题


my configuration is as below , i am getting no subscriber exception , how can i resolve ?

<bean id="Beani" class="org.util.Beani" init-method="init" />
<int:gateway id="configHelper" 
    service-interface="org.ncb.quickpay.grs.util.PartnerConfigReader"
    default-request-timeout="5000" default-reply-timeout="5000">
    <int:method name="getConfiguration" request-channel="configChannel" />
</int:gateway>

<int-jpa:retrieving-outbound-gateway 
    entity-manager="entityManager" request-channel="configChannel"
    jpa-query="select s from Setting s where  s.settingsCategory.category=:category">
    <int-jpa:parameter name="category" expression="payload['category']" />
</int-jpa:retrieving-outbound-gateway>

i am invoking this in a bean init method

public void init() throws Exception {
    System.out.println(" initialization global MAp  beni ");
    Map msgMap = new HashMap();
    msgMap.put("category", "web_service_dtl");
    Message msg = MessageBuilder.withPayload(msgMap).build();
    List<Setting> configList = configReader.getConfiguration(msg);

    if(configList!=null){
    for (Setting config : configList) {
        globalMap.put(config.getSettingsParameter().getParameterName() + "_"
                + config.getSettingsCategory().getPartnerId(), config.getParamValue());
    }
    }

    System.out.println(" map is  "+globalMap);

}

bean is defined in xml , and i am getting exception .

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Beani' defined in class path resource [grs-spring-integration.xml]: Invocation of init method failed; nested exception is org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'org.springframework.context.support.ClassPathXmlApplicationContext@23ab930d.configChannel'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:776)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at org.ncb.quickpay.grs.service.main.StartService.main(StartService.java:18)
Caused by: org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'org.springframework.context.support.ClassPathXmlApplicationContext@23ab930d.configChannel'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:81)

Please let me know how to resolve it ?


回答1:


i am invoking this in a bean init method

You must not start messaging in an init method; the application context is not fully built yet and the integration components you are using have not been started.

You can either implement ApplicationListener<ContextRefreshedEvent> and put your code there; or implement SmartLifecycle, put you bean in a late Phase and put your code in start(). Either way, the integration components will have been started by that time.

It looks like you are still trying to solve this question to load global properties. I gave you another solution there which will work, but you can't invoke messaging components before the context is started; regardless of where you do it.



来源:https://stackoverflow.com/questions/41181195/how-to-resolve-dispatcher-has-no-subscribers-for-channel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!