我面临着一个又一个的问题。让我好好记下来 -
我正在实现 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">
这在我的笔记本电脑上运行良好,但在测试虚拟机中,我们无法从互联网下载 XSD 架构文件。
所以我将架构位置更改为类路径 -
<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 已经包含了 spring-context 相关的 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>
这些 jar 未打包在主 jar 中,但可在
modules/system/layers/thirdparty/org/springframework/main/spring-context-4.3.1.RELEASE.jar.
但是为什么找不到 jar 呢?
我也尝试了阴影插件,但仍然不包含依赖项 jar - How to create spring-based executable jar with maven?
我还应该考虑什么?
我的 jar 中没有 META-INF/spring.handlers 等 Spring 相关文件。这会是问题吗?
最佳答案
我通过创建 META-INF 目录并将 spring.handlers 和 spring.schemas 文件放入其中解决了该问题。我提取了所有 spring jar,其中一些包含 spring.handlers 和 spring.schemas 文件。我连接了这些文件的内容并将它们放入 META-INF 中。
但令人惊讶的是,该项目在 eclipse 中运行,但在 VM 中运行失败。在 Eclipse 项目中,我不需要复制 jar 的 META-INF 目录中的 spring.handlers 和 spring.schemas 文件 - 它可以在没有它们的情况下工作。但在虚拟机中我需要复制文件!可能在 Eclipse 中这些文件是从 .m2 引用的,因为这些 jar 位于类路径中?有什么想法吗?
谢谢
关于java - 配置问题: Unable to locate Spring NamespaceHandler for XML schema namespace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55593266/