You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Craig R. McClanahan" <cr...@apache.org> on 2003/01/07 05:41:10 UTC
Re: server.xml- linking to a context containing a jndi resource from
another context
On 6 Jan 2003, Nick Torenvliet wrote:
> Date: 06 Jan 2003 22:52:05 -0500
> From: Nick Torenvliet <ni...@fieldstonesolutions.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
> nick@fieldstonesolutions.com
> To: Tomcat Users List <to...@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: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>