Darth Ninja
Darth Ninja

Reputation: 1039

How to inject extended enums via Spring?

I have a follow up question to this solution to extending java enums.

How do I inject the extended enums via Spring config when a bean has the interface as property. For example,

class Foo {
  Day dayProp;

  public setDayProp(Day day) {
     this.dayProp = day;
  }
}

This gives an error 'failed to convert java.lang.String to interface Day'. I've also tried specifying the entire path.

<bean id="foo1" class="Foo">
  <property name="dayProp" value="SAT" />
</bean>

Upvotes: 2

Views: 902

Answers (2)

masted
masted

Reputation: 1220

Spring uses reflection to determine the type of property anyway. Have you tried just "SAT"?

Upvotes: -1

Darth Ninja
Darth Ninja

Reputation: 1039

With a bit of experimentation, I got this working using SpEL

<property name="dayProp" value="#{ T(path.for.WeekendDay).SAT }" />

But I would love to hear of alternative solutions.

Upvotes: 4

Related Questions