了解JNDI [英] Understanding JNDI
问题描述
JNDI就像一张关于类固醇的地图吧?我使用键来查找对象的引用。
另外,什么是InitialContext?我似乎没有理解。
JNDI is like a map on steroids right? I use a key to find references to objects. Also, what is InitialContext? I don't seem to get the idea.
推荐答案
从概念上讲,JNDI就像 System.getProperties( )
关于类固醇。
Conceptually, JNDI is like System.getProperties()
on steroids.
System.getProperties()
允许你传递 String
从命令行到代码的参数。类似地,JNDI允许您在代码之外配置任意对象(例如,在应用程序服务器配置文件中),然后在代码中使用它们。
System.getProperties()
allows you to pass String
parameters to your code from the command line. Similarly, JNDI allows you to configure arbitrary objects outside of your code (for example, in application server config files) and then use them in your code.
换句话说,它是服务定位器模式的实现:您的代码从中心注册表获取环境配置的服务。
In other words, it's an implementation of Service Locator pattern: your code obtains services configured by environment from the centeral registry.
与服务定位器一样,您的代码应该有一些入口点来访问服务定位器。 InitialContext
是这个入口点:你创建 InitialContext
,然后通过查找从JNDI获取所需的服务()
。
As usually with Service Locators, your code should have some entry point to access Service Locator. InitialContext
is this entry point: you create InitialContext
and then obtain required services from JNDI with lookup()
.
这篇关于了解JNDI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!