我在Unable to locate NamespaceHandler when using context:annotation-config
运行(java -jar)一个由 maven-assembly-plugin 组装并包含我的项目及其所有依赖项的 jar 时出错。
正如其他人在 forum.springsource.org线程(消息 #7/8)上正确发现的那样,出现问题是因为存在于不同 jar 中的文件META-INF/spring.handlers
在META-INF/spring.schemas
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
是不是可以将 META-INF 文件夹放在特定的包中?如果是这样,我建议的想法(希望它适用)是将META-INF/spring.shemas
andMETA-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
这样它们在合并到一个 jar 中时不会发生冲突。你怎么看待这件事?