Announcement Announcement Module
No announcement yet.
How to set a bean property of type safe-type enum class? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to set a bean property of type safe-type enum class?

    Hi.. I'm a newbie Spring user.

    I've this class :

    public class MyClass {

    private ConfigKey theKey;

    // setter


    ConfigKey is a type-safe enum class :

    public class ConfigKey {

    private ConfigKey(int key){
    this.key = key;

    private int key;

    public static final ConfigKey KEY_1 = new ConfigKey(1);
    public static final ConfigKey KEY_2 = new ConfigKey(2);


    How should I fill the ??? below?

    <bean class="MyClass " id="myClass">
    <property name="minProcessKey">
    <property name="maxProcessKey">

  • #2
    If you want to assign instances of your enum class to a property you can use org.springframework.beans.factory.config.FieldRetr ievingFactoryBean. Have a look at the API documentation for an example.

    Alternatively, maybe this thread could be helpful (though it's about java5 enums):

    Hope that helps,
    Last edited by robyn; May 14th, 2006, 05:42 PM.