Spring NamespaceHandler issue when launching Maven

2020-08-25 14:24发布

问题:

Here's an issue I'm stuck with for multiple hours already, and by now I feel quite desperate. I migrated our application from Spring 2.5/Hiberante 3.3 to Spring 3.0.5/Hibernate 3.6. The following was done:

  • updated spring dependencies/version (now there's more than just a few dependencies)
  • updated Hibernate dependencies/version
  • updated Spring context XML files in terms of versions for 'schemaLocation'

The error I still have when launching from Eclipse IDE after different minor fixes and tunes, is as following:

Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/tx]

I looked through the other threads, and realized that such a problem arises when the specific lib (in this case spring-tx) not found in classpath, but I clearly see it in my Maven dependencies.

The next thing I did, I built the WAR as I did it for previous versions, deployed it on Tomcat, and the app worked fine!

By this I can make a conclusion that something is missing in Eclipse environment configuration. What's interesting that all complains are about spring-tx,- when I removed the single line utilizing tx namespace <tx:annotation-driven transaction-manager="transactionManager" /> .. application started fine without complains about other namespaces (of course, it didn't work fine, but at least there were no complains during the init).

Some summary about my IDE/project setup:

  • application launch performed by GWT .launch file (GWT ver 2.0.3)
  • within this launch file there're references to other projects, including serverside that has spring dependencies
  • in fact, this gwt-client project has serverside POM as parent, and as a result I see all of spring dependencies in this project's Maven Dependencies
  • GWT-client project has /war/WEB-INF/applicationContext.xml that imports other context XML resources, which are actually utilizing spring-tx

The formal question would be: what are the possible reasons why the project launch from IDE results with such errors after migrating to Spring 3x (and works fine deployed as built WAR)?

I don't expect straight answers (unless someone had exactly the same environment & problem), but guidelines, advices would be of great help!

EDIT Forgot to mention that during app startup from IDE, I have bunch of warnings like these:

[WARN] Server class 'javax.persistence.EntityManagerFactory' could not be found in the web app, but was found on the system classpath
   [WARN] Adding classpath entry 'file:/D:/maven/repository/org/hibernate/javax/persistence/hibernate-jpa-2.0-api/1.0.0.Final/hibernate-jpa-2.0-api-1.0.0.Final.jar' to the web app classpath for this session
[WARN] Server class 'org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor' could not be found in the web app, but was found on the system classpath
   [WARN] Adding classpath entry 'file:/D:/maven/repository/org/springframework/spring-orm/3.0.5.RELEASE/spring-orm-3.0.5.RELEASE.jar' to the web app classpath for this session

.. so maybe spring-tx also is not found in web-app (and found on the system classpath), but it's not added like that happened with the others? What would be the reason of this behavior?

回答1:

When developing with Maven, you should launch the DevMode from your target/${project.finalName} folder, after a call to mvn package or simply mvn war:exploded (which will copy your dependencies to the WEB-INF/lib there).
See http://code.google.com/eclipse/docs/faq.html#gwt_with_maven and http://code.google.com/p/google-web-toolkit/issues/detail?id=6619



回答2:

If you have multiple spring dependencies on your classpath, then you may be running into this issue with maven:

When using mulitple Spring dependencies, the files from META-INF (from the Spring jars) overwrite each other in an executable jar-with-dependencies

To fix this, see the comment from Chris Wilkes. You need to copy the spring.handlers and spring.schemas into your META-INF directory.