What is the purpose of JNDI

前端 未结 4 762
情书的邮戳
情书的邮戳 2020-12-07 08:15

How can you realize the usage of JNDI , with an example if possible?

4条回答
  •  生来不讨喜
    2020-12-07 08:52

    JNDI allows the simplification of a resource construct into just a name. So, it's many details group into 1 for convenience/security/etc. (aka abstraction layer)

    to realize: set up a properties list that corresponds to the predefined fields in the Jndi Context Interface. (these properties specify the settings for the jndi execution; but *not the search name)

    Properties props = new Properties();
    //field Context.INITIAL_CONTEXT_FACTORY => property name java.naming.factory.initial
        //field Context.PROVIDER_URL => property name java.naming.provider.url
    props.load(new FileInputStream("*properties file*")); //prop file in this case
    
    Context ctx = new InitialContext(props);
        Object o = ctx.lookup("*name of resource*");
    

    ideally, a specialized function would exist to maintain a LDAP directory, DNS, etc, at your organization (so a unified single mapping set services all, reducing discrepancies)

    List of JNDI Service Providers: https://www.ibm.com/support/knowledgecenter/en/SSVSD8_8.4.1/com.ibm.websphere.dtx.adapjndi.doc/concepts/c_jndi_JNDI_Service_Providers_.htm

提交回复
热议问题