Camel聚合器异常

时间:2013-06-25 16:23:06

标签: java apache-camel aggregator

我已经安装了camel(版本2.10.X),我可以使用csv和xslt处理器运行很多示例。 现在我正在尝试使用骆驼aggregator。 我已经从驼峰文档中调整了一个示例,这样当3个文件写入input目录时,它们必须聚合并发送到输出目录

我的背景如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:amq="http://activemq.apache.org/schema/core"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" />
<bean id="aggregatorStrategy" class="org.apache.camel.processor.BodyInAggregatingStrategy" />

<camel:camelContext xmlns="http://camel.apache.org/schema/spring">
    <camel:package>com.example.camel.wardemo</camel:package>

    <camel:route>
        <camel:from uri="file:/inputdir" />         
        <camel:aggregate strategyRef="aggregatorStrategy" completionSize="3">           
            <camel:correlationExpression>
                <camel:simple>header.id</camel:simple>
            </camel:correlationExpression>          
            <camel:to uri="file:/outdir" />
        </camel:aggregate>
    </camel:route>
</camel:camelContext>

但是在部署war文件时,应用程序无法启动并导致异常: (localhost_XXXXXX.log

    5.06.2013 18:14:03 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
25.06.2013 18:14:05 org.apache.catalina.core.StandardContext listenerStart
SCHWERWIEGEND: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'activemq' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:     Initialization of bean failed; nested exception is     
org.springframework.beans.factory.BeanCreationException: Error creating bean with name     'camel-1': Invocation of init method failed; nested exception is   org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.camel.processor.BodyInAggregatingStrategy] for bean with name  'aggregatorStrategy' defined in ServletContext resource [/WEB-INF/applicationContext.xml];  nested exception is java.lang.ClassNotFoundException:  org.apache.camel.processor.BodyInAggregatingStrategy

这应该是我在上下文中对此标记的引用:

<bean id="aggregatorStrategy" class="org.apache.camel.processor.BodyInAggregatingStrategy" />

我做错了什么?

谢谢!

修改

这是我的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
    <groupId>com.example.camel</groupId>
    <artifactId>CamelDemo</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>    

<groupId>com.example.camel</groupId>
<artifactId>CamelWarDemo</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>CamelDemo :: WAR Demo</name>

<dependencies>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-csv</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-camel</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-web</artifactId>
        <scope>runtime</scope>
        <type>war</type>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
    </dependency>            
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
    </dependency>  
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-maven-plugin</artifactId>
            <version>${camel-version}</version>             
        </plugin>
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${jetty-version}</version>                
            <configuration>
                <webAppConfig>
                    <contextPath>/</contextPath>
                </webAppConfig>
                <systemProperties>
                    <systemProperty>
                        <name>com.sun.management.jmxremote</name>
                        <value />
                    </systemProperty>
                </systemProperties>
                <scanIntervalSeconds>10</scanIntervalSeconds>
            </configuration>
        </plugin>
    </plugins>
</build>

1 个答案:

答案 0 :(得分:1)

问题是BodyInAggregatingStrategy不在camel-core依赖项中,因为它位于/src/test/java ...

之下