Java Spring Integration 没有为端点定义轮询器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20799737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 04:26:12  来源:igfitidea点击:

Spring Integration No poller has been defined for endpoint

javaspringspring-integrationpoller

提问by Ernest Hilvano

Hi i am having a hard time solving my xml configuration,

嗨,我很难解决我的 xml 配置问题,

here's my spring integration config xml:

这是我的 spring 集成配置 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" />

here is my main class::

这是我的主要课程::

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);
        }

    }
}

Im just simply running it using a main class, i am receiving this exception::

我只是简单地使用主类运行它,我收到了这个异常::

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.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

i am just new on learning spring integration, i dont know how to fix my configuration also..

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

采纳答案by Artem Bilan

You have several queuechannels. To receive Messages from them you should configure <poller>: global one, or for each component, which are subscribed to those queues: Poller Configuration, Poller sample

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

UPDATE:

更新:

Global poller:

全局轮询器:

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

Queue channels are splitter, router and service activator right?

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

No, channels are channels and they don't do anything with messages, from big height, of course. Messages are gotten from channels by Endpoints. In case of queueit should be PollingConsumerand the exception says exactly it. So, you have to: or add global poller, but in this case all endpoints will poll messages via the same rules, or configure <poller>for each endpoint. In your case they are components who have those queues as input-channel.

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

回答by Tomasz Janisiewicz

Annotation alternative for defining global default pooler:

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

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

    PollerMetadata pollerMetadata = new PollerMetadata();
    pollerMetadata.setTrigger(new PeriodicTrigger(10));
    return pollerMetadata;
}

回答by amitVerma

The problem is resolved by below steps-

问题通过以下步骤解决-

  1. Right click on your project in eclipse.
  2. Then Maven > Update Project.
  1. 在 Eclipse 中右键单击您的项目。
  2. 然后 Maven > 更新项目。

Note: Make sure you have xsd and jar in place as well.

注意:确保你也有 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>