Search code examples
javaspringjndiapplicationcontext

Which issue does JNDI solve that ApplicationContext does not solve in Spring?


JNDI is a mean to retrieve/store data or objects from string names. This feature is provided by the container running the application.

ApplicationContext allows the creation and retrieval of beans from their string name.

Both serve similar needs. Yet, Spring offers means to retrieve objects from JNDI. One can also access JNDI via the JndiTemplate.

Is there a real need to use JNDI in Spring? Which problem does it solve that ApplicationContext does not?


Solution

  • The Application Context would not help you in looking up a REMOTE object. It will only look for objects in the current application, which are not remote.

    See the following "Context.PROVIDER_URL". You can get access to REMOTE objects like EJBs or RMI or JMS, etc. Also, you could access any resource managed by the Java EE Container such as a DataSource.

    ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    ht.put(Context.PROVIDER_URL,"t3://HOSTNAME:PORT");