0 Replies Latest reply on Feb 22, 2009 8:26 PM by Shah din sani

    Could not get JNDI datasource working

    Shah din sani Newbie


      I am new to Jboss and at this point learning about Jboss and JSF. Currently I am working on a very small JSF application (JSF, Spring) that connects to a database (H2) and then reads and display some information from that database. Everything works fine when I perform JNDI lookup from my code as mentioned below.

      private Connection getConnectionUsingJNDI() throws Exception
       Properties properties = new Properties();
       properties.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       properties.setProperty(InitialContext.PROVIDER_URL, "jnp://localhost:1099");
       InitialContext ic = new InitialContext(properties);
       Connection con = null;
       if (ic != null) {
       DataSource ds = (DataSource) ic.lookup("java:/H2DS");
       con = ds.getConnection();
       return con;

      Next I tried to configure my JNDI lookup in Spring. Following are the steps that I took.

      Added following entry in my spring context file:
      <jee:jndi-lookup id="dSource" jndi-name="java:/H2DS" resource-ref="true"/>

      Modified my applicationContext.xml file to use new datasource.
      <bean id="employDAO" class="dao.EmployDAO">
       <property name = "dataSource">
       <ref bean="dSource"/>

      When I deploy my application, I am getting a success, however when I hit this application I am getting a null for DS. Please advice. Since i am new to Jboss, i will appriciate if you could post a detailed solution.