tags:

views:

2678

answers:

5

I have a standalone enum type defined, something like this:

package my.pkg.types;

public enum MyEnumType {
    TYPE1,
    TYPE2
}

No I want to inject a value of that type into a bean property:

<bean name="someName" class="my.pkg.classes">
   <property name="type" value="my.pkg.types.MyEnumType.TYPE1" />
</bean>

...and that didn't work :(

How should I do that?

+6  A: 

Have you tried just "TYPE1" ? I suppose spring uses reflection to determine the type of "type" anyway, so the fully qualified name seems redundant. I must admit I'm guessing, but spring generally doesn't subscribe to redundancy ;)

krosenvold
+3  A: 

You can just do "TYPE1".

JacobM
A: 

You can write Bean Editors (details are in the Spring Docs) if you want to add further value and write to custom types.

Fortyrunner
A: 

Thanks a lot Guys!! You are awesome..

+1  A: 

Use the value child element instead of the value attribute and specify the Enum class name:

<property name="residence">
<value type="SocialSecurity$Residence">ALIEN</value>
</property>
Tsering