For my first contact with the Java EE Novice, the 13 specifications of the Java EE are so mysterious.
Starting with Jndi today, let's start with a 13-spec mystery.
JNDI
JNDI (Java naming and directory Interface) Java naming and directory interface, one of the important specifications in the Java EE specification, is named
The abstract mechanism of the service.
Common Jndi Operations:
Bind (String Sname,object object), binding: The process of associating a name with an object.
Rebind (String Sname,object object), rebinding: Used to rebind the object with a name that already exists. General use
Rebind () does not use BIND (), because rebind () will not have an exception when there is a duplicate name, and bind () will report an exception.
Unbind (String sName), release: Used to release objects from the directory.
Lookup (String sName), find: Returns the total object of the directory.
Rename (String soldname,string snewname), renaming: The name used to modify the object name binding.
Namingenumeration listbindings (String sName), listing: Returns the manifest column of the specified property name object in a specific context
Table, which returns the name, class, and object itself, for applications that need to actually manipulate the object. The specific use is as follows:
Get a reference to the initial directory environment
Context cntxt = new InitialContext ();
Example:
Binding Example:
<span style= "FONT-SIZE:18PX;" >public static InitialContext Getinitialcontext () throws Namingexception {Hashtable env = new Hashtable (); Env.put (Context.initial_context_factory, "weblogic.jndi.WLInitialContextFactory"); Env.put (Context.provider_url, "t3://localhost:7001"); InitialContext context = new InitialContext (env); return context;} Get initial Contextinitialcontext InitialContext = Getinitialcontext ();//Create an object named Bank. Bank MyBank = new Bank ();//Bind the Bind object to the Jndi tree. Initialcontext.rebind ("Thebank", MyBank);</span>
Lookup Example:
public static InitialContext Getinitialcontext () throws Namingexception {Hashtable env = new Hashtable (); Env.put (Context.initial_context_factory, "weblogic.jndi.WLInitialContextFactory"); Env.put (Context.provider_url, "t3://localhost:7001"); InitialContext context = new InitialContext (env); return context;} Get initial Contextinitialcontext InitialContext = Getinitialcontext ();//Find the bound Bank object. Bank MyBank = (Bank) initialcontext.lookup ("Thebank");
JNDI function
Provides developers with a common, unified interface to find and access various naming and directory services
My understanding:
We've all used Hashtable and dictionary. They work by storing objects in the form of key and value, each of which is added by the
A value and its associated key are composed. The corresponding object can be found according to key when using.
Jndi can also understand this. He also binds the object to the Jndi tree in the form of a key value (key and value), using bind and rebind operations.
The lookup operation is followed by finding the corresponding value (object) according to key.
Each specification is an abstraction of one aspect of programming, and Jndi primarily provides lookup services. It provides a unified way for programmers to operate without
Management is LDAP, RMI, DNS, directory services, file services, objects, configuration files, and so on, we only need to know their names can be obtained and manipulated
They.
The Java EE specification requires that all Java EE containers provide the implementation of the JNDI specification. The role of JNDI in the Java EE is "switch"--J2EE Group
Common mechanism for finding other components, resources, or services at run time grounding. The primary role of JNDI in the Java EE application is to provide an indirect layer,
This makes it possible for components to discover the resources they need without knowing the indirection. In this respect, Jndi plays a similar role in appearance patterns, so
The coupling between external resources and applications can also be lifted.
Interpretation of the Java EE 13 specification Jndi