我得到了错误Unable to locate NamespaceHandler when using context:annotation-config运行(java -jar)一个由maven-assembly-plugin组装并包含我的项目及其所有依赖项的jar.
正如其他人在forum.springsource.org 线程(消息#7/8)上正确发现的那样,问题出现是因为文件META-INF/spring.handlers和META-INF/spring.schemas存在于不同的jar中,当maven-assembly-plugin在单个文件中重新打包jar时会被覆盖.
查看两个spring - *.jar文件的内容,您可以看到文件位于相对于类路径的相同位置
$ jar tf spring-oxm-3.0.3.RELEASE.jar
META-INF/spring.handlers
META-INF/spring.schemas
org/springframework/oxm/GenericMarshaller.class
...
$ jar tf spring-context-3.0.3.RELEASE.jar
META-INF/spring.handlers
META-INF/spring.schemas
org/springframework/context/ApplicationContext.class
Run Code Online (Sandbox Code Playgroud)
是不是可以将META-INF文件夹放在特定的包中?如果是这样,我建议的想法(希望它是适用的)是将META-INF/spring.shemas和META-INF/spring.handlers文件放在他们引用的包下面.
$ jar tf spring-oxm-3.0.3.RELEASE.jar
org/springframework/oxm/META-INF/spring.schemas
org/springframework/oxm/META-INF/spring.handlers
org/springframework/oxm/GenericMarshaller.class
...
$ jar tf spring-context-3.0.3.RELEASE.jar
org/springframework/context/META-INF/spring.handlers
org/springframework/context/META-INF/spring.schemas
org/springframework/context/ApplicationContext.class
Run Code Online (Sandbox Code Playgroud)
这样,在单个jar中合并时它们不会发生冲突.你怎么看待这件事?
我正在使用Spring Batch为我们的数据仓库构建累积快照,我遇到了一个我无法弄清楚的配置障碍.
我使用Spring模板项目使用STS(SpringSource Tool Suite 2.8.1)创建了一个简单的Spring Batch 项目.这些是我创建的两个xml配置文件:
发射后的context.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:batch="http://www.springframework.org/schema/batch"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
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">
<context:property-placeholder location="classpath:batch.properties" />
<context:component-scan base-package="edu.kdc.visioncards" />
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="${batch.schema.script}" />
</jdbc:initialize-database>
<batch:job-repository id="jobRepository" />
<import resource="classpath:/META-INF/spring/module-context.xml" />
Run Code Online (Sandbox Code Playgroud)
和module-context.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:batch="http://www.springframework.org/schema/batch"
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<description>Example job to get you started. It provides a skeleton for a typical batch application.</description>
<batch:job id="job1">
<batch:step …Run Code Online (Sandbox Code Playgroud) 配置问题:无法找到XML架构命名空间的Spring NamespaceHandler [http://www.springframework.org/schema/mvc].
任何人都可以告诉为什么会发生这种错误?这是我的配置.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
Run Code Online (Sandbox Code Playgroud)