现在的位置: 首页 > 综合 > 正文

mvn打包Spring程序namespace can’t be located等解决办法

2013年01月31日 ⁄ 综合 ⁄ 共 1472字 ⁄ 字号 评论关闭

当使用maven打包Spring程序的时候,打包完成之后,各种原因,程序执行不了,表现方式多种多样:

Example 1: The spring-context-2.5.xsd can't be found: 
WARN org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Ignored XML validation warning org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/context/spring-context-2.5.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
Example 2: The NamespaceHandler for the spring context namespace can't be located:
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace http://www.springframework.org/schema/context

根据jar包下META-INF中的spring.handlers和spring.schemas被覆盖的情况的不同,会出现不同的错误提示。

如想了解详细情况,请参考官方的bug地址:http://jira.codehaus.org/browse/MASSEMBLY-360

下面,我翻译一下,最方便的解决办法:

While this doesn't fix the underlying problem it does get you started:
Make a src/main/resources/META-INF/ directory
explode the spring.jar (the large one) and put the spring.handlers and spring.schemas files from there into the above directory
Now when your executable jar is built those two files will be the last ones copied over so they "win" and are included in the jar file.
A better fix would be to make a plugin that gets those two files from all the spring-xxx.jars and concats them together.

就是在创建

src/main/resources/META-INF/

文件夹,然后把spring的各个jar包下的spring.handler和spring.schemas都整合成两个较大的spring.handler和spring.schemas文件,放在刚才创建的那个文件夹下。然后就搞定了。当然,也不用一下子全处理,少哪个,就加哪个。

抱歉!评论已关闭.