无法在jboss环境中启动camel spring上下文

时间:2017-08-10 09:53:07

标签: spring jboss apache-camel

我已经创建了一个骆驼弹簧文件,如下所示。该文件使用代码中已存在的routebuilder类。它无法解析xml,因此applicationcontext无法正常启动。

<?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:tx="http://www.springframework.org/schema/tx"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:camel="http://www.camel.apache.org/schema/spring"  
       xsi:schemaLocation="http://www.springframework.org/schema/beans     
            spring-beans.xsd  http://www.springframework.org/schema/tx 
            spring-tx.xsd  http://www.springframework.org/schema/context 
            spring-context.xsd  http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring-2.19.1.xsd">

    <bean id="ValidateAndUpdateBatchRoute" class="com.camelkafka.ValidateAndUpdateBatchRoute" />
    <camel:camelContext xmlns="http://camel.apache.org/schema/spring">
        <camel:routeBuilder ref="ValidateAndUpdateBatchRoute" />
    </camel:camelContext>

</beans>

但是当启动jboss时会抛出以下异常。

16:09:20,181 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/RDAWorkFlowEjb-17.6]] (ServerService Thread Pool -- 125) JBWEB000289: Servlet startup threw load() exception: org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 68; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'camel:camelContext'.
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:196)
    at org.apache.xerces.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:132)
    at org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:390)
    at org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:322)
    at org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:281)
    at org.apache.xerces.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:446)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3271)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1993)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:724)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:283)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1653)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:324)
    at org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:845)
    at org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:768)
    at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:108)
    at org.apache.xerces.parsers.DOMParser.parse(DOMParser.java:230)
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:285)
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76) [spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:429) [spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391) [spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) [spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) [spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181) [spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217) [spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188) [spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252) [spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127) [spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93) [spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129) [spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:612) [spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:513) [spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) [spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) [spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at com.alu.oss.mdf.rda.workflow.util.WorkFlowUtil.initialize(WorkFlowUtil.java:73) [classes:]
    at com.alu.oss.mdf.rda.workflow.servlets.StartUpServlet.init(StartUpServlet.java:18) [classes:]
    at javax.servlet.GenericServlet.init(GenericServlet.java:242) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-2.jar:1.0.2.Final-redhat-2]
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1194) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1100) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3593) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3802) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:163) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
    at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:61) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
    at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:96) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [rt.jar:1.8.0_102]
    at java.util.concurrent.FutureTask.run(Unknown Source) [rt.jar:1.8.0_102]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.8.0_102]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.8.0_102]
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.8.0_102]
    at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.2.Final-redhat-1.jar:2.1.2.Final-redhat-1]

无法理解spring xml文件中缺少的内容。我已经在jboss的module.xml中为第三方依赖添加了依赖项。

2 个答案:

答案 0 :(得分:0)

http://www.camel.apache.org/schema/spring命名空间的位置更改为使用http://camel.apache.org/schema/spring/camel-spring-2.19.1.xsd! (没有www。)

答案 1 :(得分:0)

camelContext spring 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:camel="http://camel.apache.org/schema/spring"
       xsi:schemaLocation=" http://www.springframework.org/schema/beans spring-beans.xsd 
       http://camel.apache.org/schema/spring camel-spring.xsd">

    <bean id="jbossResolver" class="org.apacheextras.camel.jboss.JBossPackageScanClassResolver"/>
    <bean id="ValidateAndUpdateBatchRoute" class="com.camelkafka.ValidateAndUpdateBatchRoute" />
    <camel:camelContext>
        <camel:routeBuilder ref="ValidateAndUpdateBatchRoute" />
    </camel:camelContext>
 </beans>

camel-core和camel-spring的依赖关系如下:

Camel-core-位于org / apache / camel / core:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="org.apache.camel.core">
        <resources>
                <resource-root path="camel-core-2.19.1.jar"/>
                <resource-root path="jaxb-impl-2.2.11.jar"/>
                <resource-root path="jaxb-core-2.2.11.jar"/>
                <resource-root path="camel-jboss6-2.18.0.jar"/>
                <resource-root path="camel-spring-2.19.1.jar"/>
        </resources>
        <dependencies>
                <module name="org.springframework"/>
                <module name="org.slf4j"/>
                <module name="javax.xml.bind.api"/>
                <module name="javax.api"/>
                <module name="sun.jdk" />
                <module name="org.jboss.vfs" />
        </dependencies>
</module>

下一个驼峰 - 位于org / apache / camel / spring:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="org.apache.camel.spring">
        <resources>
                <resource-root path="camel-spring-2.19.1.jar"/>
                <resource-root path="camel-jboss6-2.18.0.jar"/>
        </resources>
        <dependencies>
                <module name="org.springframework"/>
                <module name="org.slf4j"/>
                <module name="javax.xml.bind.api"/>
                <module name="javax.api"/>
                <module name="org.apache.camel.core" />
                <module name="org.jboss.vfs" />
        </dependencies>
</module>

还要确保将camel-spring.xsd添加到类路径中。这应该如下所示开始:

ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camelContext.xml");

这对我来说很好。希望它能帮助其他人在jboss EAP中使用camel。

出于某种原因,在jboss中配置的骆驼第三方罐子没有被拿起。我不得不把罐子放在WEB-INF / lib中让它工作。