Is there a Spring dependency on Commons Collections?

I know there isn’t a true, requirement, that projects using Spring use Commons Collections. However, when looking at various examples I’ve found some interesting output in my logfiles. Very early in my logfiles I’m seeing a ClassNotFoundException on org.apache.commons.collections.map.LinkedMap. The message is at the DEBUG level; so I guess the code is looking for a LinkedMap class, not finding it, throwing the exception, and then using something else, most likely a java.util.Collection Map.

The main reason I’m asking this question is I would like to know if there is a benefit, possibly in performance, that I can gain in using the commons-collections.jar? The same question can be asked for a possible need to include edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap which you can see is also causing a ClassNotFound exception to be thrown.

See the log output below: 2007-09-21 11:24:23,754 DEBUG org.springframework.util.ClassUtils - Class [org.apache.commons.collections.map.LinkedMap] or one of its dependencies is not present: java.lang.ClassNotFoundException: org.apache.commons.collections.map.LinkedMap

2007-09-21 11:24:23,754 DEBUG org.springframework.util.ClassUtils - Class [edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap] or one of its dependencies is not present: java.lang.ClassNotFoundException: edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap

I am seeing this behaviour with the latest production release of Spring 2.0.6, and Java 1.5.0_11 running a simple HelloWorld type example. Is anybody else seeing this? Does anybody know what the story is here? If not, I’ll make sure and find out in December when I’ll have access to the Interface21 guys while attending The Spring Experience.

[tags]spring, ClassNotFoundException, LinkedMap[/tags]

4 thoughts on “Is there a Spring dependency on Commons Collections?”

  1. I can’t say for sure… but from my experience I’ve only had a need for classes in the package edu.emory.mathcs.backport.java.util.concurrent when using JRuby from Spring… so my guess it is a dependency JRuby requires on that part, not Spring.

    As for commons-collections, no clue. I really wouldn’t be surprised though. 😉

    Thanks, James

  2. Hi Erik

    Spring does not have a hard dependency on the commons collections classes. What you are seeing is just DEBUG level messages… if you have a look at the source code for the CollectionFactory class (which calls into the ClassUtils class), you will see that Spring attempts to use the ‘best’ Collection implementation that it can find based on the JVM version and what is available on the classpath.

    http://static.springframework.org/spring/docs/1.2.x/api/org/springframework/core/CollectionFactory.html

    In short, you can safely ignore these DEBUG messages. Alternatively, you can raise a JIRA issue… historically Juergen has been quick to tone down Spring’s sometimes excessive logging in response to such issues being raised.

    Cheers Rick

  3. Thanks for the comment Rick… The DEBUG message was fairly clear that things were ok, but the fact that I saw the ClassNotFoundException got me worried.

    I don’t want to go as far as raising a JIRA task but maybe I’ll just post something to the Spring Forums.

    Thanks again…

  4. Hi,

    I am using spring 1.2.6 for our application, i am getting the following exception while retriving jsp page using java 1.6 “java.lang.ClassCastException: org.apache.commons.collections.map.LinkedMap cannot be cast to java.util.HashMap”

    I am using HashMap in JSP and in java class.same cade was working fine with java 5 when we used java 6 we got ClassCastException.

    can any one help why it worked with java 5 and not working with java 6.

Leave a Reply

Your email address will not be published. Required fields are marked *