开发jms时,遇到xml配置文件的命名空间DTD定义错误_xml使用dtd
开发jms时,遇到xml配置文件的命名空间DTD定义错误由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“xml使用dtd”。
开发jms时,遇到xml配置文件的命名空间DTD定义错误
开发jms时,用到了activemq,但是在开发过程中遇到运行和eclipse校验报错的问题,找了很多资料,终于找到了解决办法。
eclipse中的校验提示错误如下:
Multiple annotations found at this line:schema_reference.4: Failed to read schema document 'http://activemq.apache.org/schema/core/activemq-core.xsd', because 1)could not find the document;2)the document could not be read;3)the root element of the document is not.我是通过spring来配置和管理jms的相关bean。首先把activemq-all-xx.jar(xx为版本号)拷入build path的lib中,然后写发送和接收代码。但是配置这段代码的时候,eclipse老是提示错误,说是找不到amp:topic的定义,或者提示打不开activemq.xsd这个文件。这个错误暂时忽略掉。在tomcat中运行时,同样提示以上错误“no declaration can be found for element 'amq:topic'”,找了很多资料后,把 xbean-spring-3.4.jar这个包加入到clapath中,重新启动后,这个错误得以解决,说明需要另外的dtd声明。但是eclipse中的校验依然存在,根据错误提示,应该是找不到或打不开activemq-core.xsd这个文件。
重新修改amq的spring配置,把命名空间和schema都作相应的修改,注意,这个命名空间和定位一定要与activemq-all-xx.jar中META-INF中的spring.schemas的最后两行一样,否则命名空间会不匹配。
修改后刷新项目并重新校验,错误提示还是存在。这时我把activemq-all-xx.jar中的activemq.xsd解压出来放在F盘根目录,然后修改eclipse的配置: 菜单中:window->preferences,在左侧的树型列表中展开xml,选择xml Catalog,在右侧的树型列表中,选中User Specified Entries,点击“Add”按钮,选择Catalog Enry,在Location中,选择F:activemq.xsd,Key Type选择Namespace Name,key中填写:http://activemq.apache.org/schema/core,点击OK确定。
继续点击Add按钮,Location同样选择F:activemq.xsd,Key Type选择Schema Location,Key框中填写:http://activemq.apache.org/schema/core/activemq-core.xsd,点击OK确定。
最后点击Xml Catalog窗口的OK按钮完成配置。现在再打开amq 的spring配置,在窗口中点击右键,选择“validate”菜单项进行校验,看看提示是不是显示了?
我的amq spring配置如下:
http://www.daodoc.com/schema/beans/spring-beans-2.0.xsd
http://www.daodoc.com/schema/jeehttp://www.daodoc.com/schema/jee/spring-jee-2.0.xsd http://activemq.apache.org/schema/corehttp://activemq.apache.org/schema/core/activemq-core.xsd">
-->
注:在修改eclipse的xml catalog配置的时候,也可以不用解压activemq-all-xx.jar中的activemq.xsd文件,在设置location的时候,直接输http://activemq.apache.org/schema/core/activemq-core-XXX.xsd即可,但前提是你本地eclipse已经缓存了该文件或者你的电脑与互联网是联通的,否则会提示错误。关于activemq的xsd定义文件,可以访问http://activemq.apache.org/schema/core/,这里面列出了所有可用的xsd版本文件,选择一个适合自己的即可。