Announcement Announcement Module
Collapse
No announcement yet.
How to set a bean property of type safe-type enum class? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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">
    <value>???</value>>
    </property>
    <property name="maxProcessKey">
    <value>???</value>>
    </property>
    </bean>

  • #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):
    http://forum.springframework.org/sho...highlight=enum

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

    Comment

    Working...
    X