Tomcat – Gaining access to jndi environment variables within a Tomcat LifecycleListener

tomcat

I'm using a LifecycleListener in tomcat to initialize some objects required by contexts in my web server. Within LifecycleListener I would like to have access to GlobalNamingResources Environment variables to keep the configuration for the server inside the server.xml file. When trying various approaches I get the following error:

javax.naming.NameNotFoundException: Name java:comp is not bound in this Context

I'm assuming that the jndi is not initialized by this stage of the server startup process. Any ideas on how to tackle this?

Best Answer

JNDI is set up in a LifecycleListener also but NamingContextListener is the last one. I don't think you can change that.

The solution is to initialize application in a ServletContextListener. This is always initialized after all LifecycleListeners are started.

You can import all the global JNDI context to the webapp using <ResourceLink>.

Related Topic