Search code examples
javajndi

Can you help me understand the purpose of java:comp/env (The Enterprise Naming Context aka ENC)?


I have been doing some reading about the JBoss Naming Service JNDI provider.

I hit something I have seen around in code a million times but I never really truly understood - the ENC.

// Obtain the application component's ENC
Context iniCtx = new InitialContext();
Context compEnv = (Context) iniCtx.lookup("java:comp/env");

I have read some information about the ENC from

Stackoverflow article with an answer that describes ENC a bit

J2EE and JNDI - The Application Component Environment

Another Stackoverflow article

However I'm really struggling to understand when and why to use the java:comp/env JNDI context. Can anyone break it down for me?


Solution

  • The purpose of the ENC is to provide an isolated, read-only namespace that the application component can rely on regardless of the type of environment in which the component is deployed.