Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last month.
The community reviewed whether to reopen this question last month and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(10)
它代表 Java 命名和目录接口。
JNDI 允许分布式应用程序以抽象的、独立于资源的方式查找服务。
最常见的用例是在 Java EE 应用程序服务器上设置数据库连接池。部署在该服务器上的任何应用程序都可以使用 JNDI 名称 java:comp/env/FooBarPool 来访问所需的连接,而无需了解有关连接的详细信息。
这有几个优点:
devl->int->test->prod
环境移动,则可以在每个环境中使用相同的 JNDI 名称并隐藏实际使用的数据库。应用程序在环境之间迁移时不必进行更改。It stands for Java Naming and Directory Interface.
JNDI allows distributed applications to look up services in an abstract, resource-independent way.
The most common use case is to set up a database connection pool on a Java EE application server. Any application that's deployed on that server can gain access to the connections they need using the JNDI name
java:comp/env/FooBarPool
without having to know the details about the connection.This has several advantages:
devl->int->test->prod
environments, you can use the same JNDI name in each environment and hide the actual database being used. Applications don't have to change as they migrate between environments.Java 命名和目录接口TM (JNDI) 是一个应用程序编程接口 (API),它为使用 JavaTM 编程语言编写的应用程序提供命名和目录功能。它被定义为独立于任何特定的目录服务实现。因此,可以通过通用方式访问各种目录(新的、新兴的和已部署的)。
上面的答案涵盖了大部分内容,但我想在这里提供架构,以便上面的内容更有意义。
要使用 JNDI,您必须拥有 JNDI 类和一个或多个服务提供程序。 Java 2 SDK v1.3 包括用于以下命名/目录服务的三个服务提供程序:
因此,基本上您创建对象并将它们注册到目录服务上,稍后您可以对其进行查找和执行操作。
The Java Naming and Directory InterfaceTM (JNDI) is an application programming interface (API) that provides naming and directory functionality to applications written using the JavaTM programming language. It is defined to be independent of any specific directory service implementation. Thus a variety of directories(new, emerging, and already deployed) can be accessed in a common way.
Most of it is covered in the above answer but I would like to provide architecture here so that above will make more sense.
To use the JNDI, you must have the JNDI classes and one or more service providers. The Java 2 SDK, v1.3 includes three service providers for the following naming/directory services:
So basically you create objects and register them on the directory services which you can later do lookup and execute operation on.
通俗地说,JNDI 基本上是一个接口,用于能够获取内部/外部资源的实例,例如
JCA 资源适配器定义的任何其他类型。
它提供了一种能够创建访问权限的语法,无论这些访问权限是内部还是外部。即(本例中的 comp/env 表示组件/环境,还有很多其他语法):
JNDI in layman's terms is basically an Interface for being able to get instances of internal/External resources such as
or any other type defined by a JCA resource adapter.
It provides a syntax in being able to create access whether they are internal or external. i.e (comp/env in this instance means where component/environment, there are lots of other syntax):
JNDI 概述
参考
JNDI Overview
Reference
什么是 JNDI?
JNDI 代表 Java 命名和目录接口。它是 J2EE 的标准。
它的基本用途是什么?
通过此 API,您可以访问多种类型的数据,如对象、设备、命名文件和目录服务,例如。 EJB 使用它来查找远程对象。 JNDI 旨在提供一个通用接口来访问现有服务,例如 DNS、NDS、LDAP、CORBA 和 RMI。
何时使用?
您可以使用JNDI来执行命名操作,包括读取操作和更新命名空间的操作。 此处描述了以下操作。
What is JNDI ?
JNDI stands for Java Naming and Directory Interface. It comes standard with J2EE.
What is its basic use?
With this API, you can access many types of data, like objects, devices, files of naming and directory services, eg. it is used by EJB to find remote objects. JNDI is designed to provide a common interface to access existing services like DNS, NDS, LDAP, CORBA and RMI.
When it is used?
You can use the JNDI to perform naming operations, including read operations and operations for updating the namespace. The following operations are described here.
我将用一个例子来解释如何使用 JNDI 来配置数据库,而无需任何应用程序开发人员知道数据库的用户名和密码。
1)我们已经在JBoss服务器的standalone-full.xml中配置了数据源。此外,我们还可以配置池详细信息。
,这个 jndi-name 及其关联的数据源对象将可用于我们的 application.application。
2)我们可以使用 JndiDataSourceLookup 类检索此数据源对象。
在我们提供 jndi-name 后,Spring 将实例化数据源 bean。
现在,我们可以根据我们的环境或要求更改池大小、用户名或密码,但这不会影响应用程序。
注意:加密的SecurityDomain,我们需要在JBoss服务器中单独配置它,就像
这是用例之一。希望它能澄清。
I will use one example to explain how JNDI can be used to configure database without any application developer knowing username and password of the database.
1) We have configured the data source in JBoss server's standalone-full.xml. Additionally, we can configure pool details also.
Now, this jndi-name and its associated datasource object will be available for our application.application.
2) We can retrieve this datasource object using JndiDataSourceLookup class.
Spring will instantiate the datasource bean, after we provide the jndi-name.
Now, we can change the pool size, user name or password as per our environment or requirement, but it will not impact the application.
Note : encryptedSecurityDomain, we need to configure it separately in JBoss server like
This is one of the use cases. Hope it clarifies.
对我来说最好的解释是 这里
什么是 JNDI
JNDI解决什么问题
The best explanation to me is given here
What is JNDI
What Issues Does JNDI Solve
命名服务将名称与对象相关联,并根据给定的名称查找对象。(RMI 注册表是命名服务的一个很好的示例。)JNDI 为许多现有的命名服务(例如 LDAP、DNS)提供了通用接口。
如果没有 JNDI,远程资源的位置或访问信息就必须在应用程序中进行硬编码或在配置中提供。维护这些信息非常繁琐且容易出错。
A naming service associates names with objects and finds objects based on their given names.(RMI registry is a good example of a naming service.) JNDI provides a common interface to many existing naming services, such as LDAP, DNS.
Without JNDI, the location or access information of remote resources would have to be hard-coded in applications or made available in a configuration. Maintaining this information is quite tedious and error prone.
我只是好奇为什么官方文档被如此忽略其中已经详细阐述了细节。
但如果您想了解这些案例,请参阅 duffymo 的回答。
及其架构
通常如何使用它< /a>.
I am just curious why the official docs are so ignored which elaborate the details meticulously already.
But if you'd like to understand the cases, please refer to duffymo's answer.
And its architecture
And normally how you use it.
Java 命名和目录接口TM (JNDI) 是一个应用程序编程接口(API),它为使用JavaTM 编程语言编写的应用程序提供命名和目录功能。它被定义为独立于任何特定的目录服务实现。因此,可以通过通用方式访问各种目录(新的、新兴的和已部署的)。
虽然 JNDI 在 Spring Boot 等轻量级容器化 Java 应用程序中发挥的作用较小,但还有其他用途。仍然使用 JNDI 的三种 Java 技术是 JDBC、EJB 和 JMS。所有这些在 Java 企业应用程序中都有广泛的用途。
例如,单独的 DevOps 团队可以管理环境变量,例如所有环境中敏感数据库连接的用户名和密码。可以在 Web 应用程序容器中创建 JNDI 资源,并将 JNDI 用作适用于所有环境的一致抽象层。
此设置允许开发人员创建和控制用于开发目的的本地定义,同时通过相同的 JNDI 名称连接到生产环境中的敏感资源。
参考 :
https://docs.oracle.com/javase/tutorial/jndi/概述/index.html
The Java Naming and Directory InterfaceTM (JNDI) is an application programming interface (API) that provides naming and directory functionality to applications written using the JavaTM programming language. It is defined to be independent of any specific directory service implementation. Thus a variety of directories--new, emerging, and already deployed--can be accessed in a common way.
While JNDI plays less of a role in lightweight, containerized Java applications such as Spring Boot, there are other uses. Three Java technologies that still use JNDI are JDBC, EJB, and JMS. All have a wide array of uses across Java enterprise applications.
For example, a separate DevOps team may manage environment variables such as username and password for a sensitive database connection in all environments. A JNDI resource can be created in the web application container, with JNDI used as a layer of consistent abstraction that works in all environments.
This setup allows developers to create and control a local definition for development purposes while connecting to sensitive resources in a production environment through the same JNDI name.
reference :
https://docs.oracle.com/javase/tutorial/jndi/overview/index.html