Hi,
I am trying to use JNDI to access some resources.I wonder if someone knows how to use
the GlobalNamingResources.
Here is a snippet from my server.xml
<GlobalNamingResources>
<!-- the file based cache for all web applications -->
<Resource name="rohas/filecache" auth="Container" type="com.rohas.cache.FileCache"
/>
<ResourceParams name="rohas/filecache">
<parameter>
<name>factory</name>
<value>com.rohas.cache.FileCacheFactory</value>
</parameter>
<parameter>
<name>cacheDir</name>
<value>/tmp/cache</value>
</parameter>
</ResourceParams>
.....
I have then defined a link to this in my context as follows :-
<Context path="" docBase="www.compuvision.co.uk" debug="0" reloadable="true"
crossContext="false" cookies="true" >
<ResourceLink name="rohas/filecache" global="rohas/filecache"
type="com.rohas.cache.FileCache" />
....
The code to load the resource is defined as follows ::-
/* Get the file cache from the context via JNDI */
initCtx = new InitialContext();
envCtx = (Context)initCtx.lookup("java:comp/env");
/* retrieve the file cache */
fileCache = (FileCache)envCtx.lookup("rohas/filecache");
The resource is loaded as part of the startup for my servlet. When I start catalina I
get the following error:-
javax.naming.NameNotFoundException: Name rohas is not bound in this Context
at org.apache.naming.NamingContext.lookup(Unknown Source)
at org.apache.naming.NamingContext.lookup(Unknown Source)
at com.rohas.util.MasterServlet.init(MasterServlet.java:76)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at org.apache.catalina.core.StandardWrapper.loadServlet(Unknown Source)
at org.apache.catalina.core.StandardWrapper.load(Unknown Source)
at org.apache.catalina.core.StandardContext.loadOnStartup(Unknown Source)
at org.apache.catalina.core.StandardContext.start(Unknown Source)
One answer could be to define the resources in each context, but this is a pain as I
am probably going to have about 6/7 contexts each of which use this shared resource.
Can anybody help ? Am I using the global resources in completely the wrong way ???
Regards,
Arshad