- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 JNDI 的新手,我阅读了 oracle 的在线资料:
http://docs.oracle.com/javase/jndi/tutorial/getStarted/overview/index.html
它说 JNDI 有两个 API:
1) JNDI API
2) JNDI SPI
此外,它说要使用 JNDI,我们应该有 JNDI 类和服务提供者。
据我了解,服务提供者是实际的资源(命名或目录),例如LDAP 或 DNS(我的理解是否正确)?
我有以下疑问:
a) JNDI API:我们编写应用程序并使用 JNDI API 进行查找等。现在,谁来实现 JNDI API?它们本身是否完整实现,即由 JDK 提供者自己或服务提供者实现?
b) JNDI SPI:它到底是什么? JNDI SPI 是否特定于服务,例如LDAP 服务器?谁提供 JNDI SPI 的实现。仅供引用,我看到了 javax.naming.spi(以及其他)的源代码,我看到有一些接口(interface)和一些类。这些 JNDI SPI 是否在应用程序端使用(比如如果我正在编写一个简单的应用程序来从 LDAP 进行查找,那么这个 jar 是否在应用程序中)
非常感谢任何帮助。
这是一个简单的 JNDI 程序。
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class JNDIExample {
public static void main(String s[]) {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
// Is "com.sun.jndi.fscontext.RefFSContextFactory" the SPI API?
// What exactly is this?
Context ctx = new InitialContext(env);
try {
// Create the initial context
Context ctx = new InitialContext(env);
// Look up an object
Object obj = ctx.lookup(name);
// Print it
System.out.println(name + " is bound to: " + obj);
} catch (NamingException e) {
System.err.println("Problem looking up " + name + ": " + e);
}
}
}
对于上面的例子,我有以下疑问:
在上面的例子中,我们主要使用javax.naming.*
东西;谁实现它们?
SPI 在哪里参与其中?
最佳答案
a) JNDI API: We write application and use JNDI API's to do lookup etc. Now, who does implement JNDI API? Are they complete implementation in itself i.e implemented by JDK providers themselves or by service providers?
由已注册 ObjectFactory 的人提供。
在 JRE 应用程序中,这可能不会超出 JRE 本身。在 Servlet 或 J2EE 容器中,它肯定会扩展以包括容器本身,用于 java:comp
资源,并且可能还有 Web 应用程序本身。
b) JNDI SPI: what exactly is it?
它是服务提供者必须实现的服务提供者接口(interface)。
Are JNDI SPI specific to a service e.g. LDAP server?
是的。
Who provides implementations of JNDI SPI.
几乎完全是 JRE 本身。
Are these JNDI SPI's used in the application side
它们可以,至少就 ObjectFactory 而言,
但这并不常见。
(like If i am writing a simple application to do lookup from LDAP, so would this jar be in application)
没有。
编辑关于您的新问题:
In this above example we are mainly using javax.naming.* stuff; who implements them?
JRE,特别是您指定的工厂类及其 friend 。
- Where is the SPI involved in this?
工厂类和 friend 实现了 SPI。
关于java - JNDI 说明 : JNDI API, JNDI SPI,服务提供商,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30616254/
我在前几天的测验中遇到了以下问题。 Consider the code fragment (assumed to be in a program in which all variables are
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 9 年前。 Improve this qu
我刚开始接触 Objective-C,一般来说是 C,所以我想这也是一个 C 问题。它更像是一个为什么的问题,而不是一个如何做的问题问题。 我注意到,在除以两个整数时,小数部分向下舍入为 0,即使结果
我是一名优秀的程序员,十分优秀!