2010-05-27 30 views
0

如何在Spring應用程序上下文文件中表示new JndiTemplate(properties).lookup(name),其中name是一個字符串變量?我可以用類似於以下的方式來表達它,當應用程序檢索到bean ID時,它提供name從上下文彈出JndiTemplate和參數化JNDI查找

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

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

回答

2

據我瞭解,你需要的東西是這樣的:

<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); 

這工作,因爲getBean可以傳遞參數給factory-method

+0

啊如果是這樣的話,我可能誤解了這個問題。我似乎還記得還支持獲取其他類的屬性,並在春季3中將它們用作變量。 – wds 2010-05-27 14:51:06