我在Unable to locate NamespaceHandler when using context:annotation-config运行(java -jar)一个由maven-assembly-plugin组装的jar并包含我的项目及其所有依赖项的错误。
Unable to locate NamespaceHandler when using context:annotation-config
maven-assembly-plugin
当其他人正确地注意到了forum.springsource.org 线程(消息#7/8)时,就会出现问题,因为文件META-INF/spring.handlers和META-INF/spring.schemas存在于不同jar中的文件在maven-assembly-plugin将jar重新打包为单个文件时会被覆盖。
forum.springsource.org
META-INF/spring.handlers
META-INF/spring.schemas
查看两个spring-*。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
是否可以将META-INF文件夹放在特定的包装中?如果是这样,我建议(希望适用)是将META-INF/spring.shemas和META-INF/spring.handlers文件放在它们所引用的包下。
META-INF/spring.shemas
$ 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中时不会发生冲突。你怎么看待这件事?
我设法使用shader插件而不是(buggy)汇编器插件摆脱了这个错误:
<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