PDA

View Full Version : JNDI


TobyM
Aug 26th, 2004, 01:02 PM
I am probably missing something very obvious but for the life of me I cannot find any information regarding this. When you specify a JndiObjectFactoryBean, you specify the jndiName but where does it pick up which JNDI provider it is using?

irbouho
Aug 26th, 2004, 02:16 PM
JndiObjectFactoryBean looks up objects using the default JNDI environment used by your container (Tomcat, Jboss, ...).
It works the same way as if you were looking up a datasource registered in tomcat from a servlet you:

//lookup using default settings
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup (path);


It is possible to override the default settings using the property environment of JndiObjectFactoryBean. environment is of type java.util.Properties.

TobyM
Aug 26th, 2004, 04:13 PM
Thanks for that - is it possible to pass the environment properties in via the application context or bean factory? I have not been able to locate any examples of this or work out what the paramterisation would be.

Thanks in Advance.

mperham
Aug 26th, 2004, 04:28 PM
<property name="environment">
<props>
<prop key="foo">bar</prop>
</props>
</property>

irbouho
Aug 26th, 2004, 04:32 PM
Absolutely,

<bean name="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:env/comp/jdbc/dataSource</value>
</property>
<property name="environment">
<props>
<prop key="key1">value1</prop>
<prop key="key2">value2</prop>
<prop key="key3">value3</prop>
</props>
</property>
</bean>


I am sorry if i was not enough clear in my first relpy.

TobyM
Aug 26th, 2004, 04:37 PM
Excellent thanks alot, for some reason I have had a complete blind spot over this. Much appreciated.