Problem Solver

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

By , 15 April 2008

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

It seems that Tomcat 5.5 and 6.0 DataSourceRealms don't like referring to JNDI resources declared in the same context. The following configuration gives me a javax.naming.NameNotFoundException:

<Context path="/">
  
  <!-- connection pool for database -->
  <Resource name="jdbc/data" auth="Container" type="javax.sql.DataSource"
            driverClassName="org.postgresql.Driver"
            url="jdbc:postgresql://localhost/test"
            username="postgres" password=""
            maxActive="5" maxIdle="2" maxWait="-1"/>

  <!-- authentication realm -->
  <Realm className="org.apache.catalina.realm.DataSourceRealm"
         dataSourceName="jdbc/data" digest="MD5"
         userTable="web_users" userRoleTable="web_user_roles"
         userNameCol="id" userCredCol="password" roleNameCol="role"/>
</Context>

However, if I move the JNDI resource up it works as expected:

<GlobalNamingResources>

  <!-- connection pool for database -->
  <Resource name="jdbc/data" auth="Container" type="javax.sql.DataSource"
            driverClassName="org.postgresql.Driver"
            url="jdbc:postgresql://localhost/test"
            username="postgres" password=""
            maxActive="5" maxIdle="2" maxWait="-1"/>
</GlobalNamingResources>
...
<Context path="/">
        
  <!-- authentication realm -->
  <Realm className="org.apache.catalina.realm.DataSourceRealm"
         dataSourceName="jdbc/data" digest="MD5"
         userTable="web_users" userRoleTable="web_user_roles"
         userNameCol="id" userCredCol="password" roleNameCol="role"/>
</Context>

Odd...

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
 

About Roger Keays

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

I am an artist, an engineer, and a student of psychology. Some projects I'm working on at the moment are Sunburnt SEO, The Game Of Your Life, Money Talks and other, top secret stuff. You can follow me via RSS or on Twitter, Facebook, and even Google+.

Add a comment

Please visit http://RogerKeays.com/blog/javax.naming.namenotfoundexception-name-jdbc-is-not-bound-in-this-context to add your comments.

Comment posted by: Shekhar, 4 years ago

why it showing this type of Message

javax.naming.NameNotFoundException: Name CustomerManagerJNDI is not bound in this Context

SEVERE: Servlet.service() for servlet action threw exception
java.lang.NoClassDefFoundError: javax/ejb/EJBHome
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1817)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:872)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1325)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at com.jlcindia.struts.delegate.SessionBeanDelegate.validateUser(SessionBeanDelegate.java:25)
    at com.jlcindia.struts.action.LoginAction.execute(LoginAction.java:29)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Unknown Source)

Comment posted by: , 7 years ago

@see tomcat-users:

Roger Keays wrote:
> Is that the intended behaviour?
Yes. If you want a realm to use a context defined datasource rather than a global one you need to set: localDataSource="true" on the realm

It is documented in the howto but not the realm docs. I'll fix that now. http://tomcat.apache.org/tomcat-6.0-doc/realm-howto.html#DataSourceRealm

Mark

grrr...

Follow Roger Keays

It'll Change Your Life

I write every Sunday about all sorts of interesting stuff. Drop me your email and you'll be the first to get my articles when they're published. It'll change your life. And it's free :)


Website Updates

Latest Poll

Is your life is better or worse because of Facebook?
Better
Worse
The same