`

active spring整合 but no declaration can be found for element amq:broker

阅读更多
activemq 5.2

最近项目要用到JMS,因为用tomcat容器,所以采用了开源的ActiveMQ  消息中间件提供JMS支持。但是在spring2.5和activemq5.2集成的时候出现了点问题,首先列出activemq-import-beans.xml的内容:



Java代码 
1.<beans xmlns="http://www.springframework.org/schema/beans"  
2.  xmlns:amq="http://activemq.org/config/1.0" 
3.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
4.  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
5.                                    http://activemq.org/config/1.0 http://activemq.apache.org/schema/core/activemq.xsd"> 

运行测试程序出现以下异常:



Java代码 
1.Caused by: org.xml.sax.SAXParseException: TargetNamespace.1: Expecting namespace 'http://activemq.org/config/1.0', but the target namespace of the schema document is 'http://activemq.apache.org/schema/core'. 
2.    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195) 
3.    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131) 
4.    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384) 
5.    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaError(XSDHandler.java:2525) 
6.    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.constructTrees(XSDHandler.java:768) 
7.    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:569) 
8.    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:552) 
9.    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.findSchemaGrammar(XMLSchemaValidator.java:2408) 
10.    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1753) 
11.    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:685) 
12.    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400) 
13.    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2740) 
14.    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:645) 
15.    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140) 
16.    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:508) 
17.    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807) 
18.    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737) 
19.    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107) 
20.    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225) 
21.    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283) 
22.    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75) 
23.    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396) 
24.    ... 22 more 



通过阅读异常信息发现时XSD名称空间不对,所以赶紧打开activemq-core-5.2.0.jar/META-INF/目录中的spring.schemas查看,发现"http\://activemq.apache.org/schema/core/activemq-core.xsd=activemq.xsd"

于是乎又打开activemq.xsd查个究竟,以下为activemq5.2的activemq.xsd文件一部分:



Java代码 
1.<xs:schema elementFormDefault='qualified' 
2.           targetNamespace='http://activemq.apache.org/schema/core' 
3.           xmlns:xs='http://www.w3.org/2001/XMLSchema' 
4.           xmlns:tns='http://activemq.apache.org/schema/core'> 



噢,原来目标名称空间不一致啊。于是赶紧去改activemq-import-beans.xml文件的配置,修改如下:





Java代码 
1.<?xml version="1.0" encoding="UTF-8"?>  
2.<beans xmlns="http://www.springframework.org/schema/beans"  
3.xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance   
4.xmlns:amq="http://activemq.apache.org/schema/core"  //这个地方很关键,amq对应的XSD名称空间名称要和activemq.xsd的一致 
5.xsi:schemaLocation="  
6.http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
7.http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq.xsd">  



呵呵,到这里以为问题已经搞定,但是运行测试后,又发现一个新的问题,异常信息如下:



Java代码 
1.org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://activemq.apache.org/schema/core/activemq.xsd', because 1) could not find the document;  
2.               2) the document could not be read;  
3.               3) the root element of the document is not <xsd:schema>. 



查看了异常信息后,发现可能是spring无法定位到http://activemq.apache.org/schema/core/activemq.xsd,于是又一次打开activemq-core-5.2.0.jar/META-INF的spring.schemas,内容如下:



Java代码 
1.http\://activemq.org/config/1.0=activemq.xsd 
2.http\://activemq.org/config/1.0/1.0.xsd=activemq.xsd 
3.http\://activemq.apache.org/schema/core=activemq.xsd 
4.http\://activemq.apache.org/schema/core/activemq-core.xsd=activemq.xsd 

呵呵,发现问题了吗?初看没啥问题,但是仔细一看,噢,原来http\://activemq.apache.org/schema/core/activemq-core.xsd=activemq.xsd 与http://activemq.apache.org/schema/core/activemq.xsd 不匹配,呵呵,知道问题根源了,现在时解决办法,解决办法有两种:

第一种:修改activemq-import-beans.xml文件的“http://activemq.apache.org/schema/core/activemq.xsd ”这句为:http://activemq.apache.org/schema/core/activemq-core.xsd(这个就是activemq jar包中spring.schemas文件的最后一行,但是注意:http\://要改为http://)



第二种:在classpath目录中,新建META-INF/spring.schemas文件,然后增加一下内容:



Java代码 
1.http\://activemq.apache.org/schema/core/activemq-core.xsd=activemq.xsd 

这个时候重新运行测试,发现一切OK。哈。。

转:http://xmuzyq.iteye.com/blog/365989
分享到:
评论

相关推荐

    解决:dubbo找不到dubbo.xsd报错

    - cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'dubbo:application'. - schema_reference.4: Failed to read schema document '...

    dubbo.xsd文件下载

    declaration can be found for element 'dubbo:application'. - schema_reference.4: Failed to read schema document 'http:// code.alibabatech.com/schema/dubbo/dubbo.xsd', because 1) could not find ...

    dubbo找不到dubbo.xsd报错

    - cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'dubbo:application'. - schema_reference.4: Failed to read schema document '...

    解决dubbo找不到dubbo.xsd报错

    - cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'dubbo:application'. - schema_reference.4: Failed to read schema document '...

    dubbo.xsd文件资源

    - cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'dubbo:application'. - schema_reference.4: Failed to read schema document '...

    spring-mvc-3.0.xsd

    cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:resources' 报错

    dubbo.xsd 约束文件 解决标签识别报红

    - cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'dubbo:application'. - schema_reference.4: Failed to read schema document '...

    使用dubbo时需要的dubbo.xsd

    使用 dubbo 时需要添加 dubbo 支持,否则会报错 。cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'dubbo:application'.

    dubbo.xsd文件

    当我们遇到描述中的错误——"cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'dubbo:reference'"时,这通常意味着XML解析器在尝试解析配置文件时找不到...

    spring配置文件解析失败报”cvc-elt.1: 找不到元素 &#39;&#39;beans&#39;&#39; 的声明”异常解决

    在Spring框架中,配置文件是核心组件之一,它定义了bean的实例化、依赖注入以及其他的设置。当遇到“cvc-elt.1: 找不到元素 'beans' 的声明”这种异常时,通常意味着Spring在尝试解析XML配置文件时遇到了问题。这个...

    sgcWebSockets4源码版,支持D7~XE10.3.2

    【sgcWebSockets4源码版】是一个用于Delphi开发的WebSocket库,适用于D7(Delphi 7)到XE10.3.2等多个版本的Delphi IDE。WebSocket是一种在客户端和服务器之间建立持久连接的协议,它允许双向通信,即服务器和客户端...

    stylelint-declaration-use-css-custom-properties:一个stylelint自定义规则,用于检查声明中css自定义属性的使用

    stylelint声明使用CSS自定义属性一个定制... /* this declaration will be highlighted */ border : 1 px solid rgb ( 0 , 255 , 0 , 0.5 ); /* this declaration will be highlighted */ animation-name : red; /* t

    实现语法分析器-编译原理

    for语句用的是枚举所有情况,你可以自行修改。 对预备工作中自然语言描述的简化C编译器的语言特性的语法,设计上下文无关文法进行描述 借助Yacc工具实现语法分析器 考虑语法树的构造: 1.语法树数据结构的设计:节点...

    spring-instrument-tomcat-4.3.14.RELEASE.jar

    spring-instrument-tomcat-... so Spring provides a custom ClassLoader that can be used by placing spring-instrument-tomcat.jar in $TOMCAT_HOME/lib and putting a loader declaration in META-INF/context.xml.

    Scala for the Impatient.pdf

    - **Variable Declaration in For Loop**: Variables can be declared within the for loop. For example: ```scala for (i ; from = 4 - i; j ) println(i * 10 + j) ``` #### Pattern Matching Pattern ...

    delphi问题常见解决

    1. **“statement expected but procedure found”**:这个错误提示表明在编译器尝试找到一个语句的地方,它却找到了一个过程(Procedure)的定义。这通常意味着你在某个过程或函数的定义中忘记了关闭的`end`关键字...

    修改后的dubbo.xsd文件,亲测可用

    错误提示:no declaration can be found for element 'dubbo:application'。 根据此错误提示进行修改后的Dubbo文件,已亲测可用。

    iOS 7开发(英文档)

    usually what you want, but there might be situations when you want to exclude files, such as when you have more than one target, like a unit-test target. Most of the time you can just accept the ...

    EurekaLog_7.5.0.0_Enterprise

    34)..Changed: EurekaLog 7 now can be installed over EurekaLog 6 automatically, with no additional actions/tools EurekaLog 7.4 (7.4.0.0), 26-January-2016 1)....Fixed: Performance issue in DLL exports...

Global site tag (gtag.js) - Google Analytics