3 Replies Latest reply on Feb 23, 2009 10:27 PM by Shah din sani

    Having problem to use JNDI datasource.

    Shah din sani Newbie

      Hi,

      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"/>
       </property>
      </bean>
      


      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.

      Sani