我们有一个普通的独立的spring应用程序,我们需要将jdbc数据源放入jndi中。 (我们使用jboss treecache,它需要数据源在jndi中)。如何在spring中声明式地将对象绑定到jndi?
一些Google搜索在spring中发现了绝大多数的jndi查找示例,其中一个对象已经放入jndi中(通过tomcat或应用服务器等),但我们需要其他方式:我有一个普通的数据源Spring bean,到其他服务,但我不能注入到TreeCache,因为它只需要从jndi。
实测值org.springframework.jndi.JndiTemplate
,其可被声明为豆,例如:
<bean id="fsJndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">com.sun.jndi.fscontext.RefFSContextFactory</prop>
<prop key="java.naming.provider.url">file:///c:\windows\temp</prop>
</props>
</property>
</bean>
但没有发现如何与它结合其他比在Java代码:从一些其他bean的初始化方法fsJndiTemplate.bind(name, obj)
。 有没有办法做到这一点声明?
http://stackoverflow.com/questions/4414115/spring-as-a-jndi-provider – Polaris878 2011-05-12 18:54:14