【发布时间】:2011-08-23 21:43:01
【问题描述】:
我们有一个普通的独立 spring 应用程序,我们需要将 jdbc 数据源放在 jndi 中。 (我们使用 jboss 树缓存,它需要数据源在 jndi 中)。
一些谷歌搜索发现大多数使用 spring 的 jndi-lookup 示例,其中一个对象已经放入 jndi(通过 tomcat 或应用程序服务器等),但我们需要其他:我有一个普通的数据源 Spring bean,我将其注入其他服务,但我不能将它注入到 TreeCache,因为它只需要来自 jndi。
找到org.springframework.jndi.JndiTemplate,可以声明为bean,例如:
<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 代码中之外,没有找到如何与它绑定:fsJndiTemplate.bind(name, obj) from init-method of some other bean。
有没有办法以声明的方式做到这一点?
【问题讨论】:
标签: java spring configuration jndi