0 Replies Latest reply: Apr 1, 2013 3:38 PM by user10624672 RSS

    Need Help in JNDI Datasource using tomcat and spring

    user10624672
      Hi,

      I am trying to connect my local database using JNDI datasource in tomcat and spring

      I have done the below configuration in Tomcat 7 server:

      In tomcat server.xml (Path: E:\apache-tomcat-7.0.35\conf) I added the below configuration

      <Resource name="UserDatabase" auth="Container"
      type="org.apache.catalina.UserDatabase"
      description="User database that can be updated and saved"
      factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
      pathname="conf/tomcat-users.xml" />

      <Resource name="jdbc/myApp" auth="Container"
      type="javax.sql.DataSource"
      driverClassName="oracle.jdbc.OracleDriver"
      url="jdbc:oracle:thin:hr@localhost:1521:XE>"
      username="testUser" password="password"
      maxActive="10" maxIdle="5"
      maxWait="60000" removeAbandoned="true"
      removeAbandonedTimeout="60" logAbandoned="true"/>


      In web.xml, I have added the below config:

      <resource-ref>
      <description>Oracle Spring JNDI Datasource</description>
      <res-ref-name>jdbc/myApp</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>


      And in my Spring context xml (ws-context.xml), added below config:

      <bean name="myDataSourceInJndi" class="org.springframework.jndi.JndiObjectFactoryBean">
      <property name="jndiName" value="java:comp/env/jdbc/myApp"/>
      </bean>

      <jee:jndi-lookup id="dataSource" jndi-name="/jdbc/myApp" resource-ref="true"/>



      In my Java code, I am trying the below code to connect DataBase:

      Context initCtx = new InitialContext();
      Context envCtx = (Context) initCtx.lookup("java:comp/env");
      DataSource ds = (DataSource) envCtx.lookup("jdbc/myApp");
      ds.getConnection();


      But I am getting the below exception while executing ****ds.getConnection();***


      java.lang.IllegalStateException: Connection factory returned null from createConnection
      at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:584)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
      at com.wipro.spring.impl.EmployeeImpl.getDetails(EmployeeImpl.java:57)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at com.sun.xml.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:246)
      at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:146)
      at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:257)
      at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:93)
      at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:598)
      at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:557)
      at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:542)
      at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:439)
      at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243)
      at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:471)
      at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
      at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
      at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:129)
      at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:160)
      at com.sun.xml.ws.transport.http.servlet.WSSpringServlet.doPost(WSSpringServlet.java:52)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
      at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1822)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:662)


      Can you please me to resolve this issue? Am I missing any configuration or any mistake in my java code please suggest your suggestions.


      Thanks