I ran into the "Unable to locate NamespaceHandler when using context:annotation-config" error using the maven-assembly-plugin to generate a runnable jar with all the dependencies included. As other people correctly spotted in this thread Spring can't resolve the namespace handler because multiple jars contain the files META-INF/spring.handlers and META-INF/spring.schemas
. When the maven-assembly-plugin repackages the jars in a single file the files with the same name are overwritten, therefore we'll have only the ones in the last file.
Looking at the content of two spring-*.jar files you can see the files sits in the same position in the classpath
Code:
$ jar tf spring-oxm-3.0.3.RELEASE.jar
META-INF/spring.handlers
META-INF/spring.schemas
org/springframework/
org/springframework/oxm/
org/springframework/oxm/GenericMarshaller.class
...
$ jar tf spring-context-3.0.3.RELEASE.jar
META-INF/spring.handlers
META-INF/spring.schemas
META-INF/spring.tooling
org/
org/springframework/
org/springframework/context/
org/springframework/context/ApplicationContext.class
org/springframework/context/ApplicationContextAware.class
I think it is possible to put the META-INF folder in any package, so the idea I'd suggest, (hope it's applicable) is to put each spring.shemas/.handlers file under the package they refer to.
Code:
$ jar tf spring-oxm-3.0.3.RELEASE.jar
org/springframework/
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/
org/springframework/
org/springframework/context/META-INF/spring.handlers
org/springframework/context/META-INF/spring.schemas
org/springframework/context/ApplicationContext.class
org/springframework/context/ApplicationContextAware.class
This way they won't conflict... what do you think about it?