开发者

Spring JndiTemplate and parameterized JNDI lookup from context

How can I represent new JndiTemplate(properties).lookup(name), where name is a string variable, in the Spri开发者_如何学JAVAng 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" />


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜