0

I am trying to use to versions of spring in the same application: the first one is a webapp with spring 2.6 and the second it a jar client, with spring 4.0.2. The client communicates with another application and will be a dependency for the webapp. The problem is that the classloader will just load one time the common classes from spring and it will certainly fail.

I tried to use ElasticSearch aproach of using shaded dependencies(maven shade plugin) and relocate spring from the client to a different package (from org.springframework to my.springframework) and the uber jar seems to be constructed fine.

The issue is that Spring is based on spring.schemas and spring.handlers for validating xml config files and loads this files from classpath (META-INF folder and this paths are hardcoded in Spring code - e.q. PluggableSchemaResolver). I modified this files to point from org.srpingframework to my.springframework.

At runtime it seems that the classloader reads these files from the webapp, which has this files but with the real spring path and the exception is something like

org.realsearch.springframework.beans.FatalBeanException: Class [org.springframework.context.config.ContextNamespaceHandler] for namespace [http://www.springframework.org/schema/context] does not implement the [my.springframework.beans.factory.xml.NamespaceHandler] interface.

To me it seems that is impossible to achieve what I am trying (use tho spring versions in the same application with one of them relocated). Any ideas here? Am I wright?:d

Cosmin Vasii
  • 1,429
  • 3
  • 14
  • 18
  • Why does the "client" needs Spring? Are you using something like Spring remoting or the `RestTemplate` maybe? This seems indeed something quite hard to achieve. You could update your web app to a more recent Spring version instead. – Stephane Nicoll May 30 '14 at 15:31
  • The client needs spring for DI and for the spring-rabbit module. The update can't be done. One other thing we were thinking here is to hack into spring and change the location for spring.schemas and spring.handlers, and to do this we were thinking at AOP (aspectj). – Cosmin Vasii Jun 01 '14 at 06:51
  • I wouldn't really start doing that. You still have to convince me why you can't upgrade a Spring 2.5-based app to 4.x (and why the client needs 4.x in the first place). Even it's always better to go with the latest and greatest, 3.2.9 should be just fine and I don't see major issue of upgrading to that from 2.5 – Stephane Nicoll Jun 01 '14 at 09:09
  • I have managed to find a solution and it is working wonderful. It's a long explanation to add, so if anyone finds himself in a similar situation ask here and I will post the solution I found – Cosmin Vasii Oct 07 '14 at 08:13
  • @CosminVasii , please post your solution. My problem is that weblogic uses an older version of spring. I managed to relocate spring classes, but spring.handlers still pointing to older classes. – Sandro Simas Sep 07 '15 at 21:45
  • I need to check some old code, because it was long time ago. I wrote some AOP to intercept the calls to the spring class and made it point to my local files. I will came back tomorrow with the exact answer. Hope it doesn't burn – Cosmin Vasii Sep 08 '15 at 14:37

0 Answers0