0

这已经被问过几次了,但我仍然无法弄清楚问题是什么。我想运行一个使用 Apache Camel 2.12.1 和 Spring 3.2.4 作为独立 Java 应用程序的示例应用程序。我正在使用JDK7u25。

这是我的spring application-config.xml:

<?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:context="http://www.springframework.org/schema/context"
xmlns:camel="http://camel.apache.org/schema/spring"
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-3.2.xsd
                    http://camel.apache.org/schema/spring
                    http://camel.apache.org/schema/spring/camel-spring-2.12.1.xsd">

<camel:camelContext id="myCamelContext">
  <camel:route>
    <from uri="file://C:/Local Disk E/TestData/Source?noop=true" />
    <to uri="file://C:/Local Disk E/TestData/Destination" />
  </camel:route>
</camel:camelContext>

<bean id="sampleBeanID" class="myCamelProject.SampleBean" />

</beans>

但是,我收到以下异常:

Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 15 in XML document from URL [file:/C:/My%20Workspace/ICSCamel/bin/resources/application-config.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 15; columnNumber: 68; cvc-complex-type.2.4.a: Invalid content was found starting with element 'from'. One of '{"http://camel.apache.org/schema/spring":description, "http://camel.apache.org/schema/spring":from, "http://camel.apache.org/schema/spring":aop, "http://camel.apache.org/schema/spring":aggregate, "http://camel.apache.org/schema/spring":bean, "http://camel.apache.org/schema/spring":doCatch, "http://camel.apache.org/schema/spring":when, "http://camel.apache.org/schema/spring":choice, "http://camel.apache.org/schema/spring":otherwise, "http://camel.apache.org/schema/spring":convertBodyTo, "http://camel.apache.org/schema/spring":delay, "http://camel.apache.org/schema/spring":dynamicRouter, "http://camel.apache.org/schema/spring":enrich, "http://camel.apache.org/schema/spring":filter, "http://camel.apache.org/schema/spring":doFinally, "http://camel.apache.org/schema/spring":idempotentConsumer, "http://camel.apache.org/schema/spring":inOnly, "http://camel.apache.org/schema/spring":inOut, "http://camel.apache.org/schema/spring":intercept, "http://camel.apache.org/schema/spring":interceptFrom, "http://camel.apache.org/schema/spring":interceptToEndpoint, "http://camel.apache.org/schema/spring":loadBalance, "http://camel.apache.org/schema/spring":log, "http://camel.apache.org/schema/spring":loop, "http://camel.apache.org/schema/spring":marshal, "http://camel.apache.org/schema/spring":multicast, "http://camel.apache.org/schema/spring":onCompletion, "http://camel.apache.org/schema/spring":onException, "http://camel.apache.org/schema/spring":pipeline, "http://camel.apache.org/schema/spring":policy, "http://camel.apache.org/schema/spring":pollEnrich, "http://camel.apache.org/schema/spring":process, "http://camel.apache.org/schema/spring":recipientList, "http://camel.apache.org/schema/spring":removeHeader, "http://camel.apache.org/schema/spring":removeHeaders, "http://camel.apache.org/schema/spring":removeProperty, "http://camel.apache.org/schema/spring":resequence, "http://camel.apache.org/schema/spring":rollback, "http://camel.apache.org/schema/spring":route, "http://camel.apache.org/schema/spring":routingSlip, "http://camel.apache.org/schema/spring":sample, "http://camel.apache.org/schema/spring":setBody, "http://camel.apache.org/schema/spring":setExchangePattern, "http://camel.apache.org/schema/spring":setFaultBody, "http://camel.apache.org/schema/spring":setHeader, "http://camel.apache.org/schema/spring":setOutHeader, "http://camel.apache.org/schema/spring":setProperty, "http://camel.apache.org/schema/spring":sort, "http://camel.apache.org/schema/spring":split, "http://camel.apache.org/schema/spring":stop, "http://camel.apache.org/schema/spring":threads, "http://camel.apache.org/schema/spring":throttle, "http://camel.apache.org/schema/spring":throwException, "http://camel.apache.org/schema/spring":to, "http://camel.apache.org/schema/spring":transacted, "http://camel.apache.org/schema/spring":transform, "http://camel.apache.org/schema/spring":doTry, "http://camel.apache.org/schema/spring":unmarshal, "http://camel.apache.org/schema/spring":validate, "http://camel.apache.org/schema/spring":wireTap}' is expected.
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at myCamelProject.SpringStandaloneExample.main(SpringStandaloneExample.java:28)
Caused by: org.xml.sax.SAXParseException; lineNumber: 15; columnNumber: 68; cvc-complex-type.2.4.a: Invalid content was found starting with element 'from'. One of '{"http://camel.apache.org/schema/spring":description, "http://camel.apache.org/schema/spring":from, "http://camel.apache.org/schema/spring":aop, "http://camel.apache.org/schema/spring":aggregate, "http://camel.apache.org/schema/spring":bean, "http://camel.apache.org/schema/spring":doCatch, "http://camel.apache.org/schema/spring":when, "http://camel.apache.org/schema/spring":choice, "http://camel.apache.org/schema/spring":otherwise, "http://camel.apache.org/schema/spring":convertBodyTo, "http://camel.apache.org/schema/spring":delay, "http://camel.apache.org/schema/spring":dynamicRouter, "http://camel.apache.org/schema/spring":enrich, "http://camel.apache.org/schema/spring":filter, "http://camel.apache.org/schema/spring":doFinally, "http://camel.apache.org/schema/spring":idempotentConsumer, "http://camel.apache.org/schema/spring":inOnly, "http://camel.apache.org/schema/spring":inOut, "http://camel.apache.org/schema/spring":intercept, "http://camel.apache.org/schema/spring":interceptFrom, "http://camel.apache.org/schema/spring":interceptToEndpoint, "http://camel.apache.org/schema/spring":loadBalance, "http://camel.apache.org/schema/spring":log, "http://camel.apache.org/schema/spring":loop, "http://camel.apache.org/schema/spring":marshal, "http://camel.apache.org/schema/spring":multicast, "http://camel.apache.org/schema/spring":onCompletion, "http://camel.apache.org/schema/spring":onException, "http://camel.apache.org/schema/spring":pipeline, "http://camel.apache.org/schema/spring":policy, "http://camel.apache.org/schema/spring":pollEnrich, "http://camel.apache.org/schema/spring":process, "http://camel.apache.org/schema/spring":recipientList, "http://camel.apache.org/schema/spring":removeHeader, "http://camel.apache.org/schema/spring":removeHeaders, "http://camel.apache.org/schema/spring":removeProperty, "http://camel.apache.org/schema/spring":resequence, "http://camel.apache.org/schema/spring":rollback, "http://camel.apache.org/schema/spring":route, "http://camel.apache.org/schema/spring":routingSlip, "http://camel.apache.org/schema/spring":sample, "http://camel.apache.org/schema/spring":setBody, "http://camel.apache.org/schema/spring":setExchangePattern, "http://camel.apache.org/schema/spring":setFaultBody, "http://camel.apache.org/schema/spring":setHeader, "http://camel.apache.org/schema/spring":setOutHeader, "http://camel.apache.org/schema/spring":setProperty, "http://camel.apache.org/schema/spring":sort, "http://camel.apache.org/schema/spring":split, "http://camel.apache.org/schema/spring":stop, "http://camel.apache.org/schema/spring":threads, "http://camel.apache.org/schema/spring":throttle, "http://camel.apache.org/schema/spring":throwException, "http://camel.apache.org/schema/spring":to, "http://camel.apache.org/schema/spring":transacted, "http://camel.apache.org/schema/spring":transform, "http://camel.apache.org/schema/spring":doTry, "http://camel.apache.org/schema/spring":unmarshal, "http://camel.apache.org/schema/spring":validate, "http://camel.apache.org/schema/spring":wireTap}' is expected.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.emptyElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
    ... 14 more

有人可以指导我在哪里做错了吗?

[编辑]:

package myCamelProject;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author Parag.Joshi
 *
 */
public class SpringStandaloneExample {

    //private static final String CONFIG_PATH = System.getProperty("user.dir") + "/src/myCamelProject/application-config.xml";
    private static final String CONFIG_PATH = "classpath*:resources/application-config.xml";

    /**
     * @param args
     */
    public static void main(String[] args) {
        // get the spring context
        final ApplicationContext springContext = new ClassPathXmlApplicationContext(CONFIG_PATH);
        // get the bean
        final SampleBean myBean = (SampleBean) springContext.getBean("sampleBeanID");
        // call a method of the bean
        System.out.println(myBean.run("Hello World - "));
    }
}
4

1 回答 1

2

你需要更新

<from uri="file://C:/Local Disk E/TestData/Source?noop=true" />
<to uri="file://C:/Local Disk E/TestData/Destination" />

<camel:from uri="file://C:/Local Disk E/TestData/Source?noop=true" />
<camel:to uri="file://C:/Local Disk E/TestData/Destination" />
于 2013-10-21T11:20:50.673 回答