繁体   English   中英

配置问题:无法找到XML模式命名空间的Spring NamespaceHandler

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM