We have a regular standalone spring application, and we need to put the jdbc datasource in jndi. (we use trekache jboss and it needs a data source for jndi).
Some googling searches found the most examples of jndi-lookup with spring, where the object is already placed in jndi (using tomcat or application server, etc.), but we need another way: I have a simple spring bean data source that I am adding to other services, but I can’t insert it in TreeCache because it is needed only from jndi.
Found org.springframework.jndi.JndiTemplate , which can be declared as a bean, for example:
<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>
but did not find how to associate with it, except in the java code: fsJndiTemplate.bind(name, obj) from the init method of another bean. Is there any way to do this declaratively?
java spring configuration jndi
yetanothercoder
source share