找不到以下项的终结点:direct://DistributeOrderXML,请检查类路径是否包含所需的Camel组件jar

disho6za  于 2023-02-12  发布在  Apache
关注(0)|答案(2)|浏览(197)

DistributeOrderXML.java

public static void main(String[] args) throws Exception{

    ApplicationContext appContext = new ClassPathXmlApplicationContext("SpringRouteContext.xml");

    CamelContext camelContext = SpringCamelContext.springCamelContext(appContext, false);

    try {
        camelContext.start();
        ProducerTemplate orderProducerTemplate = camelContext.createProducerTemplate();
        InputStream orderInputStream = new FileInputStream(ClassLoader.getSystemClassLoader().getResource("order.xml").getFile());
        orderProducerTemplate.sendBody("direct:DistributeOrderXML", orderInputStream);
    } finally {
        camelContext.stop();
    }

}

SpringRouteContext.xml

<camelContext
    xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="direct:DistributeOrderXML" />
        <log message="Split by Distribute Order" />
        <split>
            <xpath>//order[@product = 'Oil']/items</xpath>
            <to uri="file:src/main/resources/order/" />
            <to uri="stream:out" />
        </split>
    </route>
</camelContext>

ERROR CONSOLE

Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[From[direct:DistributeOrderXML] -> [To[stream:... because of No endpoint could be found for: direct://DistributeOrderXML, please check your classpath contains the needed Camel component jar. at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:123) at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:353) at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:327) at org.apache.camel.impl.engine.AbstractCamelContext.doInit(AbstractCamelContext.java:2598) at org.apache.camel.support.service.BaseService.init(BaseService.java:83) at org.apache.camel.impl.engine.AbstractCamelContext.init(AbstractCamelContext.java:2431) at org.apache.camel.support.service.BaseService.start(BaseService.java:111) at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2448) at org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:121) at org.apache.camel.spring.CamelContextFactoryBean.start(CamelContextFactoryBean.java:373) at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:420) at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:94) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:403) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:360) at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:897) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:144) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:85) at DistributeOrderXML.main(DistributeOrderXML.java:16)
Caused by: org.apache.camel.NoSuchEndpointException: No endpoint could be found for: direct://DistributeOrderXML, please check your classpath contains the needed Camel component jar. at org.apache.camel.impl.engine.AbstractCamelContext.doGetEndpoint(AbstractCamelContext.java:880) at org.apache.camel.impl.engine.AbstractCamelContext.getEndpoint(AbstractCamelContext.java:764) at org.apache.camel.support.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:57) at org.apache.camel.reifier.AbstractReifier.resolveEndpoint(AbstractReifier.java:166) at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:259) at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:117) ... 21 more

gab6jxml

gab6jxml1#

您使用的是哪个版本的Camel?如果版本高于Camel 3,您需要在pom文件中导入camel-direct,因为direct组件已经从camel-core模块中移出。
https://camel.apache.org/manual/latest/camel-3-migration-guide.html#_modularization_of_camel_core

w8biq8rn

w8biq8rn2#

我也遇到过这个错误,我的问题是我没有包含端点中使用的特定Camel组件的依赖项。
所以在这种情况下
创建路由route1失败:路线(路线1)[从[直接:分发订单XML]-〉[到[流:...
意味着Camel无法将"stream:..."识别为端点。您必须在pom. xml中添加此依赖项:

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-stream</artifactId>
<version>x.x.x</version>
</dependency>

相关问题