Announcement Announcement Module
Collapse
No announcement yet.
Defining Enum value in bean definition (Spring 3.0.5.RELEASE) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Defining Enum value in bean definition (Spring 3.0.5.RELEASE)

    I have an enum defined as

    Code:
    public enum Monsoon {
    	SPRING(1),
    	SUMMER(2),
    	AUTUMN(3),
    	FALL(4),
    	WINTER(5);
    	
       private final Integer seasonId;
       	
       public Integer seasonId() {
    	return seasonId;
       }
       
       private Monsoon(Integer seasonId) {
          this.seasonId = seasonId;		
       }
    }
    i had defined the enum as property to a bean as follows;

    Code:
    <bean id="weather" class="org.weather.WeatherIntereceptor">
        <property name="seasonId">
            <value type="org.weather.Monsoon">#{SPRING.seasonId}</value>
        </property>
    </bean>
    But the above throws an exception saying SPRING no property or field definition

    Where am i going wrong ?

  • #2
    I don't know if this helps you, but if you instead defined a "season" instance variable on "WeatherInterceptor" of type "Monsoon" (which really should be "Season"), then you could do this:
    Code:
    <bean id="weather" class="org.weather.WeatherIntereceptor">
        <property name="season" value="SPRING"/>
    </bean>

    Comment


    • #3
      That would'nt return 1 ( seasonId integer value ) that I was looking for, it would only give me SPRING.

      Comment


      • #4
        Of course it wouldn't return "1", it would return the actual enum value. I got this information right out of the Spring documentation. Search for "Setting a bean property or constructor arg from a field value" in the documentation.

        Comment


        • #5
          Agreed dkarr. I refactored the interceptor to contain enum instance inplace of featureId.
          That gives me access to featureId from the enum. Thanks!

          Comment

          Working...
          X