问题描述
我出现错误Unable to locate NamespaceHandler when using context:annotation-config
运行(java -jar)由maven-assembly-plugin组装的jar,其中包含我的项目及其所有依赖项.
I got the error Unable to locate NamespaceHandler when using context:annotation-config
running (java -jar) a jar assembled by the maven-assembly-plugin and containing my project and all its dependencies.
当其他人正确地出现在forum.springsource.org 线程(消息#7/8)发生问题是因为maven-assembly-plugin将jar重新打包到一个文件中时,存在于不同jar中的文件META-INF/spring.handlers
和META-INF/spring.schemas
被覆盖了.
As other people correctly spotted on the forum.springsource.org thread (message #7/8) the problem occurs because the files META-INF/spring.handlers
and META-INF/spring.schemas
that are present in different jars, get overwritten when the maven-assembly-plugin repackages the jars in a single file.
查看两个spring-*.jar文件的内容,您可以看到这些文件相对于类路径位于相同的位置
Looking at the content of two spring-*.jar files you can see the files sits in the same position relatively to the classpath
$ 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
是否可以将META-INF文件夹放在特定的包装中?如果是这样,我建议(希望适用)是将META-INF/spring.shemas
和META-INF/spring.handlers
文件放在它们所引用的包下.
Isn't it is possible to put the META-INF folder in a specific package? If so the idea I'd suggest, (hope it's applicable) is to put the META-INF/spring.shemas
and META-INF/spring.handlers
files under the package they refer to.
$ 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
这样,它们合并到单个jar中时不会发生冲突.您如何看待?
This way they won't conflict when merged in a single jar. What do you think about it?
推荐答案
我设法使用shader插件而不是(buggy)汇编器插件摆脱了这个错误:
I managed to get rid of the bug using the shader plugin instead of the (buggy) assembler plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>at.seresunit.lecturemanager_connector.App</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
我想我在springsource论坛上找到了解决方案..自从我查找它以来已经有一段时间了..我真的不记得作者了.无论如何都对他表示敬意:p
I think I found the solution on the springsource forums.. it has been quite some time since I looked it up.. can't really remember the author. Kudos to him anyways :p
欢呼
这篇关于避免在单个jar中合并多个spring依赖项时覆盖spring.handlers/spring.schemas的想法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!