tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: server.xml- linking to a context containing a jndi resource from another context
Date Tue, 07 Jan 2003 04:41:10 GMT


On 6 Jan 2003, Nick Torenvliet wrote:

> Date: 06 Jan 2003 22:52:05 -0500
> From: Nick Torenvliet <nick@fieldstonesolutions.com>
> Reply-To: Tomcat Users List <tomcat-user@jakarta.apache.org>,
>      nick@fieldstonesolutions.com
> To: Tomcat Users List <tomcat-user@jakarta.apache.org>
> Subject: server.xml- linking to a context containing a jndi resource from
>     another context
>
> Hi, I have a sever.xml that contains two webapps, one with a jndi
> resource to a mysql data base and another that I would like to link into
> that resource with with.  I understand I might have to use a global link
> into the later context from the former but I am unsure how to proceed,
> does anyone have some example code I can take a look at?
>

First, you need to be using Tomcat 4.1 for this -- 4.0 does not support
shared JNDI resources.  You'll also need to reorganize things in
server.xml slightly for this to work.

Next, declare the data source itself (the <Resource> and <ResourceParams>
elements) in the <GlobalNamingResources> section of server.xml.  Then, use
a <ResourceLink> from *both* webapps.  Resource links only go from a
webapp to the global resources, not from one webapp to another.

  <GlobalNamingResources>
    ...
    <!-- The global name of this database is "MyDatabase" -->
    <Resource name="MyDatabase" type="javax.sql.DataSource" .../>
    <ResourceParams name="MyDatabase">
      ... <!-- Data source config parameters go here -->
    </ResourceParams>
    ...
  </GlobalNamingResources>



  <Context path="/foo" ...>
    ...
    <!-- This app uses "java:comp/env/jdbc/Customers" -->
    <!-- from within the webapp -->
    <ResourceLink name="jdbc/Customers" global="MyDatabase"/>
    ...
  </Context>



  <Context path="/bar" ...>
    ...
    <!-- This app uses "java:comp/env/jdbc/Employess" but it -->
    <!-- shares the same connection pool -->
    <ResourceLink name="jdbc/Employees" global="MyDatabase"/>
    ...
  </Context>



Craig


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


Mime
View raw message