我正在用Spring創建一個獨立的Sava應用程序來處理JDBC訪問。該應用程序在每個測試中都能正常工作,並且我決定需要一個jar來部署我們的客戶。另一個「無法找到Spring NamespaceHandler」錯誤
它們在類路徑中可能沒有彈簧,所以我使用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目錄/主/資源。並將其放置在目標/包名稱基礎上。
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中缺少頭文件。請張貼這個文件,或者至少是標題和根元素以及一些樣本。 – 2010-07-26 13:42:05