1
<util:map id="myMap" key-type="com.myClass.Foo.myEnum" value-type="com.myClass.Foo">
    <entry>
        <key>
            <value type="com.myClass.Foo.myEnum">ONE</value>
        </key>
        <ref bean="myObj"/>
    </entry>
</util:map>

Java:

package com.myClass
public class Foo {
    public enum myEnum {ONE, TWO;}
}

I am trying to create a map from Spring 2.5.

Map<myEnum, Foo> myMap;

I am getting

nested exception is java.lang.ClassNotFoundException:com.myClass.Foo.myEnum

I definitely have com.myClass.Foo.myEnumin com.myClass.Foo I don't know why I am getting java.lang.ClassNotFoundException.

halfer
  • 19,824
  • 17
  • 99
  • 186
codereviewanskquestions
  • 13,460
  • 29
  • 98
  • 167
  • possible duplicate [spring2.5 how to set a map with enum as key and an obj as value](http://stackoverflow.com/questions/19601077/spring2-5-how-to-set-a-map-with-enum-as-key-and-an-obj-as-value) – Reimeus Oct 26 '13 at 00:58

1 Answers1

3

Your enum class' fully qualified name is

com.myClass.Foo$myEnum

not

com.myClass.Foo.myEnum

Switch it and it will work. Spring uses reflection, with Class.forName() to get the Class object for your class and to instantiate an object. forName() expects a fully qualified name. Read this to understand why your class name contains a $.

Note that in newer versions of Spring, there's a catch block that catches the ClassNotFoundException and tries forName again after replacing the last . with a $.

Community
  • 1
  • 1
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724