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

会有一股神秘感。 提交于 2019-12-24 13:43:18

问题


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?


回答1:


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");



回答2:


It's a question of scope. Spring's scope is limited to your application inside its container. JNDI is a global naming API that can plug into many different naming/directory architectures.



来源:https://stackoverflow.com/questions/11315755/which-issue-does-jndi-solve-that-applicationcontext-does-not-solve-in-spring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!