如何解决 Dispatcher 没有频道订阅者? [英] how to resolve Dispatcher has no subscribers for channel?

查看:66
本文介绍了如何解决 Dispatcher 没有频道订阅者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的配置如下,我没有收到订阅者异常,我该如何解决?

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>

我在 bean init 方法中调用它

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 是在 xml 中定义的,我得到了异常.

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)

请告诉我如何解决它?

推荐答案

我在 bean init 方法中调用它

i am invoking this in a bean init method

您不得在 init 方法中开始消息传递;应用程序上下文尚未完全构建,您正在使用的集成组件尚未启动.

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.

您可以实现 ApplicationListener 并将您的代码放在那里;或者实现 SmartLifecycle,把你的 bean 放在 Phase 的后期,然后把你的代码放在 start() 中.无论哪种方式,集成组件都将在那时启动.

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.

这篇关于如何解决 Dispatcher 没有频道订阅者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆