tags:

views:

212

answers:

1

How can I represent new JndiTemplate(properties).lookup(name), where name is a string variable, in the Spring application context file? Can I express it in a way similar to the following, where the application provides name when it retrieves the bean ID?

<util:properties id="applicationProperties"
    location="classpath:application.properties"/>

<jee:jndi-lookup id="connectionFactory"
    jndi-name="${name}"
    environment-ref="applicationProperties"
    resource-ref="false" />
+2  A: 

As far as I understand, you need something like this:

<bean id = "jndiTemplate" class = "org.springframework.jndi.JndiTemplate">
    <property name = "environment" ref = "applicationProperties" />
</bean>

<bean id = "objectFromJndi" factory-bean = "jndiTemplate" factory-method = "lookup"
    scope = "prototype" />

-

ApplicationContext ctx = ...;
Object o = ctx.getBean("objectFromJndi", name);

This will work because getBean can pass arguments to factory-method.

axtavt
ah if that's the case, I may have misunderstood the question. I seem to recall there's also support for grabbing properties of other classes and using them as variables in spring 3.
wds