Java Naming and Directory Service (JNDI)

zhaozj2021-02-16  64

In J2EE, JNDI's purpose is to find registration resources of J2EE servers (such as EJB, etc.) 1. JNDI introduction naming service provides an object naming mechanism so you can get it without knowing the object location. And use objects. As long as the object is registered on the naming server, you must know the address of the name server and the JNDI name registered on the naming server. You can find this object to get its reference, thus using the services it provides. Use JNDI to find all objects that have been registered on the naming server. JNDI is a Java API defined for the Java and directory service, is an abstract mechanism for named services. We can use JNDI to operate naming services without interacting with the underlying naming server, greatly alleviating programmers' pressure. Second, apply JNDI 1. Starting and closing the JNDI server starts JNDI servers while launching the J2EE server with J2EE -Verbose. In general, the J2EE server is started while the J2EE server is started. J2EE -Stop Close JNDI Server 2. Get the initial environment of the name service Contect CTX = new initailContext (); this starter environment is the default naming service. If you want to change the class (or manufacturer) of the JNDI service and provide a naming server for JNDI services, the following methods can be used: HashTable env = new hashtable (); env.initial_context_factory, "com.sun.enterprise.naming .SerialinitContextFactory "); // Specify the class name env.put (Context.Provider_URL," LocalHost: 1099 ") that provides a naming service; / / Specifies the server name and port Context CTX = New InitialContext (ENV) for naming service. Object binding to the Bind (String Name, Object O) method, binding the object o to the name name: import javax.naming. *; Public class testjndi {public static void main (string [] args) {Try {Context CTX = new initialContext (); ctx.bind ("abc", "java1"); // Bind Java1 string to ABC} catch (namingexception e) {E.PrintStackTrace ();}}}

转载请注明原文地址:https://www.9cbs.com/read-17246.html

New Post(0)