Sunday, April 27, 2008

appfuse 1.8.1 ehcache NoSuchMethodError

Problem:
I installed appfuse-light-all 1.8.1, installed acegi security, and ajax. After doing a build i get the following error when Spring starts up:

Error creating bean with name 'userManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]
.... bunch of other errors ...
Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: net.sf.ehcache.Cache.<init>

Solution:
The problem here is that i am using an older version of ehcache for some reason. Doing a bit more digging shows that i have the following versions of ehcache in my M2 repository:
[M2_REPO]/net/sf/ehcache/ehcache/1.2.3/
[M2_REPO]/net/sf/ehcache/ehcache/1.3.0/

version 1.2.3 is what is messing things up for me, it gets loaded by Spring first and causes the error. Deleting that directory does not work because "ant deploy" does the following if the dependency is missing:

Buildfile: build.xml
[artifact:dependencies] Downloading: net/sf/ehcache/ehcache/1.2.3/ehcache-1.2.3.jar
[artifact:dependencies] Downloading: net/sf/ehcache/ehcache/1.2.3/ehcache-1.2.3.jar

Now, since i dont know how to use MAVEN, i cant remove the code that fetches the old version, so i do the evil hack to prevent it from being created:

remove the directory "1.2.3", make a copy of "1.3.0" directory, call it "1.2.3". rename all the files inside to say 1.3.0 instead of 1.2.3.

Also, if you are deploying to tomcat as a directory, you might need to go into the webapps directory in tomcat, locate your app, and its WEB-INF and delete ehcache-1.2.3.jar thats is probably there now.

Now you can use appfuse.

if anyone knows of a better way to solve this, leave a comment.

2 comments:

  1. With Maven2 it could be done with the following snippet of dependency specification:

    <dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache</artifactId>
    <version>1.3.0</version>
    </dependency>
    <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate</artifactId>
    <version>3.2.6.ga</version>
    <exclusions>
    <!-- Excluding ehCache version 1.2.3, becuase it's not compatible with Spring 2.x -->
    <exclusion>
    <artifactId>ehcache</artifactId>
    <groupId>net.sf.ehcache</groupId>
    </exclusion>
    </exclusions>
    </dependency>

    ReplyDelete
  2. very cool stuff. thanks anonymous

    ReplyDelete