J2EE or J2SE? JNDI works with both (from javaworld)

Source: Internet
Author: User
Thank you for your correction!
-----------------------------
J2EE or J2SE? JNDI works with both
JNDI (Java Naming and Directory Interface) allows applications to access various Naming and Directory services through a common Interface. The following features represent the JNDI architecture. Like JDBC (Java Database Connectivity), JNDI is not a service, but an interface. It allows applications to use standard APIs to access many different directory service providers. Although Sun provides adapters such as LADP, DNS, and CORBA to connect to existing directory service providers, just as JDK contains JDBC, it contains the JNDI interface, but does not include the JNDI service provider. However, you can choose to use one of the free or open source JNDI vendors to your J2SE application.
JNDI is the adhesive used to integrate J2EE applications. JNDI is designed to support applications with high dynamic assembly and deployment, and various components can be added and updated frequently without rebuilding the entire system. The naming service serves as a component registration center to help organize enterprise-level applications. J2EE applications generally use JNDI in the following aspects:
# Store application configuration information in a centralized and hierarchical database
# As a repository of shared activity objects among different application components, these components can run in different JVM or different systems
# As an existing directory service, such as an LDAP interface (access external services in special ways)
Like J2EE applications, larger and more dynamic J2SE applications will benefit from the loose coupling and dynamic binding characteristics brought by the dynamic directory service.
A simple JNDI example
It is easy to store and trace objects from the JNDI namespace. First, obtain the namecontext (naming context) of the JNDI, and then use bind () and lookup () method to store and trace objects, as shown in Listing 1:
Listing 1. Store and retrieve objects from a JNDI namespace
Import javax. naming .*;
Public void createName () throws NamingException {
Context context = new InitialContext ();
Context. bind ("/config/applicationName", "MyApp ");
  }
Public String getName () throws NamingException {
Context context = new InitialContext ();
Return (String) context. lookup ("/config/applicationName ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.