13

嗨,我很难解决我的 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

我只是学习弹簧集成的新手,我也不知道如何修复我的配置..

4

3 回答 3

23

用于定义全局默认池的注释替代方法:

@Bean(name = PollerMetadata.DEFAULT_POLLER)
public PollerMetadata defaultPoller() {

    PollerMetadata pollerMetadata = new PollerMetadata();
    pollerMetadata.setTrigger(new PeriodicTrigger(10));
    return pollerMetadata;
}
于 2015-11-17T09:21:03.500 回答
12

你有几个queue频道。要从他们那里接收消息,您应该配置<poller>:全局一个,或者为订阅这些队列的每个组件配置:轮询器配置轮询器示例

更新:

全局轮询器:

<int:poller default="true" fixed-delay="50"/>

队列通道是分离器、路由器和服务激活器,对吗?

不,频道就是频道,当然,它们不会对消息做任何事情。消息由Endpoints 从通道中获取。万一queue它应该是PollingConsumer并且异常说明了它。因此,您必须: 或添加全局轮询器,但在这种情况下,所有端点都将通过相同的规则轮询消息,或<poller>为每个端点配置。在您的情况下,它们是将这些队列作为input-channel.

于 2013-12-27T12:27:23.450 回答
1

问题通过以下步骤解决 -

  1. 在eclipse中右键单击您的项目。
  2. 然后 Maven > 更新项目。

注意:确保您也有 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>
于 2016-12-10T19:09:40.647 回答