Wednesday, April 22, 2015

Upgrade from Spring 2.5.x to Spring 4.1.x

I am upgrading Spring libraries of a critical project from Spring 2.5.x to the latest available release which is Spring 4.1.6 right now. One of the major issues I faced is that the packaging strategy was changed in Spring 3.0 release. Earlier, a single spring.jar with all jars and required libraries was provided, but this was discontinued from the 3.0 release. Now we would need to include each jar individually as per requirements - one jar for all situations doesn't exist anymore.

So, now you need to download individual spring component jars from the Maven Repository. The jars required are:
  1. spring-aop.jar
  2. spring-beans.jar
  3. spring-context.jar
  4. spring-core.jar
  5. spring-expression.jar
  6. aopalliance-1.0.jar - third-party jar
The third-party jar aopalliance-1.0 is required only if you use org.springframework.aop and it can be downloaded from here. This was earlier on bundled in the spring.jar and so now has to be added separately as required.

You can download the corresponding javadoc and source files by going to the Maven website and searching for:
  • g:"org.springframework" AND v:"4.1.6.RELEASE" - for Spring components
  • g:"aopalliance" - for aopalliance


Now that all the required jars are downloaded, spring-core jar will need to be included in most projects; here is a simple guide to when to include rest of the jars.

Add spring-beans.jar to classpath when you see the below or similar error during compilation:
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.NoSuchBeanDefinitionException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)


Add spring-context.jar to classpath when you see the below or similar error during compilation:
Caused by: java.lang.ClassNotFoundException: org.springframework.context.access.ContextSingletonBeanFactoryLocator
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)


Add spring-expression.jar to classpath when you see the below or similar error during compilation:
Caused by: java.lang.ClassNotFoundException: org.springframework.expression.ParserContext
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)


Add spring-aop.jar to classpath when you see the below or similar error during compilation:
The type org.springframework.aop.TargetSource cannot be resolved. It is indirectly referenced from required .class files
OR

Caused by: java.lang.ClassNotFoundException: org.springframework.aop.framework.ProxyFactoryBean


Add aopalliance-1.0.jar to classpath when you see the below or similar error during compilation:
The type org.aopalliance.aop.Advice cannot be resolved. It is indirectly referenced from required .class files
OR

Caused by: java.lang.ClassNotFoundException: org.aopalliance.intercept.MethodInterceptor


That's it - you should be all set and upgraded to the latest version of Spring after this exercise - no code change required!

1 comment:

for ict 99 said...

The effectiveness of IEEE Project Domains depends very much on the situation in which they are applied. In order to further improve IEEE Final Year Project Domains practices we need to explicitly describe and utilise our knowledge about software domains of software engineering Final Year Project Domains for CSE technologies. This paper suggests a modelling formalism for supporting systematic reuse of software engineering technologies during planning of software projects and improvement programmes in Final Year Project Centers in Chennai.

Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Corporate TRaining Spring Framework the authors explore the idea of using Java in Big Data platforms.
Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai

LinkWithin

Related Posts Plugin for WordPress, Blogger...