Friday, 1 July 2011

A java.lang.NoSuchMethodError from a Spring WebApp

I was working on a Spring MVC web app recently when I got the following exception:
java.lang.NoSuchMethodError: org.springframework.web.context.ConfigurableWebApplicationContext
        .setId(Ljava/lang/String;)V
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(
        ContextLoader.java:264)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(
        ContextLoader.java:197)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(
        ContextLoaderListener.java:47)

It occurred when I was deploying my EAR fie to my Weblogic Server. Looking at the exception doesn’t really tell you very much and it took a bit of digging to get a clue to the solution.

The cause was a reference to a version 2.5.6 Spring JAR file in one of the parent POM files in my Maven build tree, when I’m supposed to be using version 3.0.5.RELEASE.

In this case, the solution was to simply change the Spring version from 2.5.6 to the current 3.0.5.RELEASE (actually ${spring.version} as I use properties to define versions).

If the version reference is in a POM file over which you have no control, then take a look at this blog entry.

No comments: