【发布时间】:2014-08-18 14:40:51
【问题描述】:
我环顾四周,但我还没有找到可以为我解决这个问题的解决方案。我有一个使用 Spring 的 Maven 项目,我调用了 assembly-single 并构建了一个可运行的 jar。该项目在 IDE 中运行良好,但是当我将其作为可运行 jar 运行时,出现以下异常:
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 8 in
XML document from class path resource [properties.xml] is invalid; nested excep
tion is org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 62; cvc-elt.
1.a: Cannot find the declaration of element 'beans'.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadB
eanDefinitions(XmlBeanDefinitionReader.java:396)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:334)
[...]
我的 properties.xml 文件如下所示。请注意,我的 schemaLocation 正确,第 8 行是 http://www.springframework.org/schema/context
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<context:property-placeholder
location="classpath:test.properties" system-properties-mode="OVERRIDE"/>
<!-- -->
</beans>
【问题讨论】:
-
您使用的是哪个 Spring 版本?
-
我相信 3.2.3.RELEASE