I have a standalone enum type defined, something like this:
package my.pkg.types; public enum MyEnumType { TYPE1, TYPE2 }
Now, 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 Inject an Enum into a spring bean?
Enum ValuesYou can assign different values to enum member. A change in the default value of an enum member will automatically assign incremental values to the other members sequentially.
Enums are not beans because they have no default constructor (hence CDI does not know how to construct them,) and there is no standard way to resolve which enumerated value should be injected by default (Unless there is only one value, but this is still not supported due to the lack of default constructor.)
Have you tried just "TYPE1"? I suppose Spring uses reflection to determine the type of "type" anyway, so the fully qualified name is redundant. Spring generally doesn't subscribe to redundancy!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With