【发布时间】:2011-03-21 02:19:03
【问题描述】:
我正在使用 Spring 创建一个独立的 Sava 应用程序,以处理 JDBC 访问。该应用程序在每次测试中都能正常运行,我决定需要一个 jar 来部署我们的客户端。
他们的类路径中可能没有 spring,所以我使用 maven-assembly-plugin 来处理带有依赖项的 jar 创建。
但是当我尝试运行应用程序时:
java -jar target/myproject-0.0.1-SNAPSHOT-jar-with-dependencies.jar
这会引发以下错误:
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/p]
Offending resource: class path resource [applicationContext.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
...and so on to the database access class of this project.
applicationContext.xml 文件位于 projectbase/src/main/resources 中。并将其放置在目标/包名基础上。
applicationContext.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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">
<bean id="dataSourceDesenv" class="org.apache.commons.dbcp.BasicDataSource"... />
<bean id="simpleJdbcDaoSupport" class="org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport"
p:dataSource-ref="dataSourceDesenv" />
<bean id="simpleJdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
<constructor-arg ref="dataSourceDesenv" />
</bean>
</beans>
【问题讨论】:
-
该错误意味着 applicationContext.xml 中缺少标头。请发布此文件,或至少发布标题和根元素以及一些示例。