嗨,我很难解决我的 xml 配置,
这是我的弹簧集成配置 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
我只是学习弹簧集成的新手,我也不知道如何修复我的配置..