我的配置如下,我没有订户异常,我该如何解决?
<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方法中调用它
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中定义,我得到了异常。
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)
请告诉我如何解决?
答案 0 :(得分:2)
我在bean init方法中调用它
您不得以init
方式开始发送消息;应用程序上下文尚未完全构建,并且您使用的集成组件尚未启动。
您可以实施ApplicationListener<ContextRefreshedEvent>
并将代码放在那里;或者实现SmartLifecycle
,将你的bean放在迟到的Phase
中,并将你的代码放在start()
中。无论哪种方式,集成组件都将在那时开始。
看起来您仍在尝试解决this question以加载全局属性。我给了你另一个可行的解决方案,但你不能在上下文启动之前调用消息组件;不管你在哪里做。