wood burning stoves 2.0*
The moose likes Tomcat and the fly likes Global Resources Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Global Resources" Watch "Global Resources" New topic
Author

Global Resources

David Sheltby
Ranch Hand

Joined: Oct 19, 2011
Posts: 34
Hi,

I have 2 webapps. I have a JNDI Resource for a connection pool defined in tomcat/conf/context.xml. So far, all code within both webapps have had no issues of using that resource to access the database. Now, I've added a (DataSource)Realm to the context of one of the webapps to be used for user authentication. This realm should use the global resource to connect to the database, however I get an exception "Name jdbc is not bound in this Context" when it looks up the resource; so I moved that resource from tomcat/conf/context.xml to tomcat/conf/server.xml#GlobalNamingResources. I read that anything defined in GlobalNamingResources would be global to all contexts. Now, the realm defined in my webapp context can see the JDNI resource, however the code in my webapps cannot.

I just need one JNDI resource which can be used by all the webapps as well as anything defined in their contexts (i.e. DataSourceRealm). How can I do this?

Thanks
David Sheltby
Ranch Hand

Joined: Oct 19, 2011
Posts: 34
So I managed to resolve it by adding the Resource to server.xml#GlobalNamingResources, and then adding a ResourceLink in each webapps context.xml, pointing to the global Resource (see below). If there is another way please let me know. Thanks

webapps context.xml
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Global Resources
 
Similar Threads
Possible to deploy a partially-expldoed WAR file?
Error confguring multiple contexts/data sources in Tomcat 5
DatasourceRealm just ain't working
Using global datasource in web-app DataSourceRealm
tomcat connection pooling