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?
Joined: Oct 19, 2011
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