Interview Questions

Spring JNDI Datasource Configuration in JBOSS

In this article let's discuss about configuring a JNDI Datasource from JBOSS in a Spring application.

Let's first create the following oracle-ds.xml (assume the db is Oracle) XML file.














The above file creates a Datasource referred by the JNDI name "OracleDS" during runtime. This file should be placed in the JBOSS-HOME/server/default/deploy directory.

Now in any Spring application, we can get the Datasource by configuring the beans in Spring context file.


<beans xmlns=""

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/OracleDS"/>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">

<constructor-arg ref="dataSource"/>



In the tag "jee:jndi-lookup", the jndi-name specified in the oracle-ds.xml file should be given. This Datasource can be used by the other DAO beans in the application.

Copy ojdbc14.jar in JBOSS-HOME\server\default\lib directory.

In this way, Datasources for other databases can be configured in JBOSS and used in Spring applications using JNDI.