PDA

View Full Version : Spring EL: resolution of bean reference in indexer



martinahrer
Mar 3rd, 2010, 01:29 PM
I'm trying to use Spring EL for solving a configuration problem and need an EL expression containing a bean reference as index of a map bean.



<util:map id="map">
<entry key="A" value="A-value" />
<entry key="B" value="B-value" />
</util:map>

<bean id="selector" class="java.lang.String">
<constructor-arg value="A" />
</bean>

<bean id="selected" class="java.lang.String">
<constructor-arg value="#{map[selector]}" />
</bean>


@ContextConfiguration(locations = { "classpath:springel.xml" })
public class SpringElIndexedPropertyTest extends AbstractJUnit4SpringContextTests {

@Resource
private String selected;

@Test
public void testSelected() {
assertEquals("A-value", selected);
}
}
Is this something that is supported ?
An expression like #{map['A']} works perfectly fine. So I guess the parser needs some shaping!