开发者

Spring JndiTemplate and parameterized JNDI lookup from context

开发者 https://www.devze.com 2023-01-01 01:43 出处:网络
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 followi

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

精彩评论

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