通常,Application Server 上執行的應用程式需要存取儲存在外部 JNDI 儲存庫中的資源。例如,一般的 Java 物件可能會以 Java 模式儲存在 LDAP 伺服器中。外部 JNDI 資源元素允許使用者配置此類外部資源儲存庫。外部 JNDI 工廠必須實作 javax.naming.spi.InitialContextFactory 介面。
使用外部 JNDI 資源的範例為:
<resources> <!-- external-jndi-resource element specifies how to access J2EE resources -- stored in an external JNDI repository. The following example -- illustrates how to access a java object stored in LDAP. -- factory-class element specifies the JNDI InitialContext factory that -- needs to be used to access the resource factory. property element -- corresponds to the environment applicable to the external JNDI context -- and jndi-lookup-name refers to the JNDI name to lookup to fetch the -- designated (in this case the java) object. --> <external-jndi-resource jndi-name="test/myBean" jndi-lookup-name="cn=myBean" res-type="test.myBean" factory-class="com.sun.jndi.ldap.LdapCtxFactory"> <property name="PROVIDER-URL" value="ldap://ldapserver:389/o=myObjects" /> <property name="SECURITY_AUTHENTICATION" value="simple" /> <property name="SECURITY_PRINCIPAL", value="cn=joeSmith, o=Engineering" /> <property name="SECURITY_CREDENTIALS" value="changeit" /> </external-jndi-resource> </resources>