This is a simple process but if you try and search on the web you will come across various incomplete solutions which will leave you more confused than you already were. This configuration involves just four simple steps that I will walk through to help you set up JNDI on Jboss. I am using Jboss 4.3, but this should be valid for other version of Jboss as well.

I have a web application which is built on Spring 3.2 and uses Hibernate 4. To set up a new JNDI configuration we will first create a datasource xml file. This file needs to be deployed in Jboss/Deploy folder along with your war file.

Step 1:

Create a datasource file oracle-ds.xml. The content of the file will look like this

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE datasources PUBLIC “-//JBoss//DTD JBOSS JCA Config 1.5//EN” “http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd&#8221;>

 

    jdbc/listener-dss

    jdbc:oracle:thin:@dbsrvossdevl:1521:US91

    oracle.jdbc.driver.OracleDriver

    myuser

    mypassword

    5

    50

    10

    org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter

   

      Oracle9i

   

 

 

Explanation: jdbc/listener-dss . This line tells what is the jndi name that we are going to use across configuration files.

 

Step** 2:** Now open your web.xml file and add the resource-ref. This tells that jee container that your web application is using JNDI.

Your web.xml should be under WEB-INF folder. Add the below lines in your web.xml (see the highlighted section). This step is common whether you use Jboss or Tomcat or Websphere or any other application server.

 

<?xml version=”1.0″ encoding=”UTF-8″?>

  xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee

  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&#8221;>

  ACN Web Application

 

   

        listener

        org.springframework.web.servlet.DispatcherServlet

        1

   

 

   

        listener

        /

   

 

   

        contextConfigLocation

        /WEB-INF/listener-servlet.xml

   

   

        Listener Database

        jdbc/listener-dss

        javax.sql.DataSource

        Container

   

 

   

        org.springframework.web.context.ContextLoaderListener

   

 

 

    index.jsp

 

 

 

Step** 3:** Next we will update the Spring context xml file to tell the Spring container that it needs to do a JNDI look up. My Spring context file name is listener-servlet.xml and this is under WEB-INF folder. Add the following(See highlighted section)

 

       xmlns:context=”http://www.springframework.org/schema/context&#8221;

       xmlns:mvc=”http://www.springframework.org/schema/mvc&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;

       xmlns:tx=”http://www.springframework.org/schema/tx&#8221;

       xmlns:p=”http://www.springframework.org/schema/p&#8221;

       xsi:schemaLocation=”http://www.springframework.org/schema/beans

        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

        http://www.springframework.org/schema/context

        http://www.springframework.org/schema/context/spring-context-3.0.xsd

        http://www.springframework.org/schema/mvc

        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

        http://www.springframework.org/schema/tx

        http://www.springframework.org/schema/tx/spring-tx.xsd “>

   

   

    tx:annotation-driven/

   

            class=”org.springframework.web.servlet.view.InternalResourceViewResolver”>

       

            /WEB-INF/pages/

       

       

            .jsp

       

   

   

       

       

           

                org.hibernate.dialect.Oracle10gDialect

                true

           

       

       

   

   

       

   

   

          p:sessionFactory-ref=”sessionFactory”>

   

   

 

Step 4: This is the crucial step. If you are using Jboss then it requires that you tell the web container that Jboss will provide the datasource .xml file where you have defined your jndi properties. Create a new file jboss-web.xml. Place this file under WEB-INF folder. The contents of the file whould like this.

<?xml version=”1.0″ encoding=”UTF-8″?>

   

        jdbc/listener-dss

        javax.sql.DataSource

        java:/jdbc/listener-dss

   

That’s all we need to do.

 

~~~~ Ciao.