Which issue does JNDI solve that ApplicationContex

2019-08-02 19:02发布

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?

2条回答
女痞
2楼-- · 2019-08-02 19:14

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.

查看更多
等我变得足够好
3楼-- · 2019-08-02 19:23

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");
查看更多
登录 后发表回答