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.

1

1 Answer 1

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 $.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.