tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lorrin Nelson <lhn-pub...@the-fam.net>
Subject Context problem: java:comp not bound??
Date Thu, 01 May 2003 19:34:10 GMT
Hi all -

I've lost access to my JNDI web app context. I thought unless you 
explicitly set useNaming="false" when defining your Context that you should 
always be able to retrieve java:comp/env. I could until a couple days ago, 
now I can't and after countless hours of searching I'm still clueless. When 
is or isn't java:comp/env accessible from inside a webapp?

If I issue the commands from inside my webapp:
	ctx = new InitialContext();
	(DataSource)ctx.lookup("java:comp/env/jdbc/spw");

I get: javax.naming.NameNotFoundException: Name java:comp is not bound in 
this Context

I get the same error trying to get the web app context itself:
	Context envContext = (Context) ctx.lookup ("java:comp/env");


Since the code hasn't really changed and it worked just a few days ago, I 
assume it's a problem with either my server.xml or my web.xml, but for the 
life of me I can't figure out what it is.

I explicitly set the useNaming attribute to true in my <Context> element, 
but it didn't help. I have tried both defining the resources I want to 
access inside the <Context> element and inside the <Server> element. Right 
now they're in the Server element:

server.xml snippet (some <parameter>s clipped out for brevity):

   <!-- Global JNDI resources -->
   <GlobalNamingResources>
       <!-- create java:comp/env/jdbc/spw in the InitialContext -->
     <Resource name="jdbc/spw"
        auth="Container"
        type="javax.sql.DataSource"
        description="Database access for SPW project"/>

     <ResourceParams name="jdbc/spw">
       <parameter>
	<name>factory</name>
	<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
       </parameter>

       <!-- MySQL dB username and password for dB connections  -->
       <parameter>
        <name>username</name>
        <value>spw</value>
       </parameter>
       <parameter>
        <name>password</name>
        <value>spw</value>
       </parameter>

       <!-- Class name for mm.mysql JDBC driver -->
       <parameter>
	 <name>driverClassName</name>
	 <value>org.gjt.mm.mysql.Driver</value>
       </parameter>

       <!-- The JDBC connection url for connecting to your MySQL dB.
	   The autoReconnect=true argument to the url makes sure that the
	   mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
	   connection.  mysqld by default closes idle connections after 8 hours.
	   -->
       <parameter>
	<name>url</name>
	<value>jdbc:mysql://localhost:3306/spw?autoReconnect=true</value>
       </parameter>
     </ResourceParams>
   </GlobalNamingResources>


Then inside my web.xml webapp element I reference the resource:

   <resource-ref>
     <description>DataSource used for all database access</description>
     <res-ref-name>jdbc/spw</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
   </resource-ref>



Besides those three elements in server.xml and web.xml, are there any other 
steps needed to make resources available? I've tried both Tomcat 4.0 and 
4.1, but no luck either way. Thanks!!

-Lorrin


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message