[英]Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
[英]Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace
我一個接一個地面臨許多問題。 讓我正確記錄下來-
我正在實現Springframework緩存,這是我原來的SpringCacheConfig.xml-
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:hz="http://www.hazelcast.com/schema/spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.hazelcast.com/schema/spring http://www.hazelcast.com/schema/spring/hazelcast-spring.xsd">
這在我的筆記本電腦上可以正常工作,但是在測試VM中,我們無法從Internet下載XSD模式文件。
所以我將schemalocations更改為classpath-
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:hz="http://www.hazelcast.com/schema/spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans classpath:spring-beans.xsd
http://www.springframework.org/schema/cache classpath:spring-cache.xsd
http://www.springframework.org/schema/context classpath:spring-context.xsd
http://www.hazelcast.com/schema/spring classpath:hazelcast-spring.xsd">
所以現在XSD文件被拾取了。 但是下載的spring-context.xsd文件具有以下內容-
<xsd:import namespace="http://www.springframework.org/schema/beans" schemaLocation="https://www.springframework.org/schema/beans/spring-beans-4.3.xsd"/>
<xsd:import namespace="http://www.springframework.org/schema/tool" schemaLocation="https://www.springframework.org/schema/tool/spring-tool-4.3.xsd"/>
因此,我再次將它們移至類路徑。
經過這些更改后,如果現在執行我們的代碼,則會收到以下錯誤-
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
Offending resource: class path resource [SpringCacheConfig.xml]
我曾嘗試通過許多以前的文章解決此問題,但未能解決。
pom已經包含了與春季相關的jar-
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${springframework.version}</version>
</dependency>
這些罐子沒有包裝在主罐子中,但可以從以下位置獲得
modules / system / layers / thirdparty / org / springframework / main / spring-context-4.3.1.RELEASE.jar。
但是為什么找不到罐子呢?
我也嘗試了shade插件,但是仍然不包括依賴罐- 如何用Maven創建基於Spring的可執行罐?
我還要考慮什么?
我在jar中沒有META-INF / spring.handlers等與Spring相關的文件。 可能是問題嗎?
我通過創建META-INF目錄並將spring.handlers和spring.schemas文件放入其中來解決了該問題。 我提取了所有的彈簧罐,其中一些具有這些spring.handlers和spring.schemas文件。 我將這些文件的內容串聯起來,並將它們放在META-INF中。
但是令人驚訝的是,該項目在Eclipse中運行,但在VM中卻沒有。 在eclipse項目中,我不需要復制jar的META-INF目錄中的spring.handlers和spring.schemas文件-它可以在沒有它們的情況下工作。 但是在VM中,我需要復制文件! 這些文件可能是在Eclipse中從.m2引用的,因為這些jar位於類路徑中? 任何想法?
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.