嗨,我很难解决我的xml配置,
这是我的spring integration config xml:
<context:annotation-config />
<context:component-scan base-package="hk.com.test.spring.integration" />
<int:channel id="orders" />
<int:channel id="drinks" />
<int:channel id="hotDrink">
<int:queue capacity="5" />
</int:channel>
<int:channel id="coldDrink">
<int:queue capacity="10" />
</int:channel>
<bean id="drinkRouter" class="hk.com.test.spring.integration.DrinkRouter" />
<bean id="orderSplitter" class="hk.com.test.spring.integration.OrderSplitter" />
<bean id="barista" class="hk.com.test.spring.integration.Barista" />
<int:gateway id="cafe" service-interface="hk.com.test.spring.integration.Cafe" />
<int:splitter input-channel="orders" ref="orderSplitter"
method="split" output-channel="drinks" />
<int:router input-channel="drinks" ref="drinkRouter" method="resolveItemChannel" />
<int:service-activator input-channel="coldDrink"
ref="barista" method="prepareColdDrink" />
<int:service-activator input-channel="hotDrink"
ref="barista" method="preparehotDrink" />
这是我的主要课程::
public class Main {
public static void main(String args[]) {
System.out.println("Hello");
// load the Spring context
ApplicationContext context = new ClassPathXmlApplicationContext(
"spring-config2.xml");
Cafe cafe = (Cafe) context.getBean("cafe");
for (int i = 1; i <= 100; i++) {
Order order = new Order(i);
order.addItem(DrinkType.LATTE, false);
order.addItem(DrinkType.MOCHA, true);
cafe.placeOrder(order);
}
}
}
我只是简单地使用主类运行它,我收到此异常::
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.config.ConsumerEndpointFactoryBean#2': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No poller has been defined for endpoint 'org.springframework.integration.config.ConsumerEndpointFactoryBean#2', and no default poller is available within the context.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:589)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at hk.com.novare.spring.integration.main.Main.main(Main.java:16)
Caused by: java.lang.IllegalArgumentException: No poller has been defined for endpoint 'org.springframework.integration.config.ConsumerEndpointFactoryBean#2', and no default poller is available within the context.
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.integration.config.ConsumerEndpointFactoryBean.initializeEndpoint(ConsumerEndpointFactoryBean.java:220)
at org.springframework.integration.config.ConsumerEndpointFactoryBean.afterPropertiesSet(ConsumerEndpointFactoryBean.java:175)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
... 12 more
我只是学习弹簧集成的新手,我也不知道如何修复我的配置..
答案 0 :(得分:13)
用于定义全局默认池的注释替代方法:
@Bean(name = PollerMetadata.DEFAULT_POLLER)
public PollerMetadata defaultPoller() {
PollerMetadata pollerMetadata = new PollerMetadata();
pollerMetadata.setTrigger(new PeriodicTrigger(10));
return pollerMetadata;
}
答案 1 :(得分:11)
您有多个queue
个频道。要从他们接收消息,您应该配置<poller>
:global one,或者为订阅这些队列的每个组件配置:Poller Configuration,Poller sample
更新:
全球投票人:
<int:poller default="true" fixed-delay="50"/>
队列通道是分路器,路由器和服务激活器吗?
不,频道是频道,当然,它们不会对消息做任何事情。消息是通过Endpoint
s从频道获取的。在queue
的情况下,它应该是PollingConsumer
,并且例外说明了它。因此,您必须:或添加全局轮询器,但在这种情况下,所有edpoints将通过相同的规则轮询消息,或为每个端点配置<poller>
。在您的情况下,他们是具有input-channel
答案 2 :(得分:1)
通过以下步骤解决问题 -
注意:确保你也有xsd和jar。
<int-stream:stdin-channel-adapter id="producer" channel="messageChannel" >
<int:poller id="defaultPoller" default="true" fixed-rate="200" />
</int-stream:stdin-channel-adapter>