Sun Java System Application Server Enterprise Edition 8.1 2005Q2 管理指南

關於外部 JNDI 儲存庫和資源

使用外部 JNDI 儲存庫和資源

通常,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>

Procedure建立外部資源

  1. 在 管理主控台 的左窗格中,為要修改的 JNDI 配置開啟 Application Server 實例。

  2. 開啟 [JNDI] 並選取 [外部資源]。

    任何已經建立的外部資源會在右側窗格中列示。

  3. 若要建立新的外部資源,按一下 [新建]。

  4. 在 [JNDI 名稱] 欄位中,輸入用於存取資源的名稱。

    此名稱將註冊到 JNDI 命名服務中。

  5. 在 [資源類型] 欄位中,輸入完全合格的類型定義,如上面範例中所示。

    [資源類型] 定義遵循的格式為 xxx.xxx

  6. 在 [JNDI 查找] 欄位中,輸入要在外部儲存庫中查找的 JNDI 值。

    例如,在建立一個與外部儲存庫連線的外部資源時,為了測試某個 Bean 類別,[JNDI 查詢] 可能會如下所示: cn=testmybean.

  7. 在 [工廠類別] 欄位中,輸入 JNDI 工廠類別外部儲存庫 (例如,com.sun.jndi.ldap)。

    此類別可實作 javax.naming.spi.ObjectFactory 介面。

  8. 在 [描述] 欄位中,為要建立的資源輸入描述。

    此描述是字串值,最多可以包含 250 個字元。

  9. 在 [附加特性] 區段,增加特性名稱和值。

  10. 標示 [啟用外部資源] 核取方塊,以啟用外部資源。

  11. 按一下 [確定] 以儲存外部資源。

    如果已在叢集或獨立實例上部署外部資源,則可以使用 [目標] 標籤管理目標。此標籤將在建立外部資源之後顯示。透過輸入目標名稱並按一下 [確定] 來設定目標。

等效的 asadmin 指令

create-jndi-resource

Procedure編輯外部資源

  1. 在 管理主控台 的左窗格中,為要修改的 JNDI 配置開啟 Application Server 實例。

  2. 開啟 [JNDI] 並選取 [外部資源]。

    任何已經建立的外部資源會在右側窗格中列示。

  3. 若要編輯外部資源,請在右側窗格中按一下檔案名稱。

  4. 編輯 [資源類型] 欄位、[JNDI 查找] 欄位、[工廠類別] 欄位或 [描述] 欄位。

  5. 標示 [啟用外部資源] 核取方塊,以啟用外部資源。

  6. 按一下 [儲存] 以儲存對外部資源的變更。

Procedure刪除外部資源

  1. 在 管理主控台 的左窗格中,開啟 [JNDI] 標籤。

  2. 按一下 [外部資源]。

    任何已經建立的外部資源會在右側窗格中列示。

  3. 請按一下要刪除資源的名稱旁邊的方塊。

  4. 按一下 [刪除]。此外部資源即被刪除。

等效的 asadmin 指令

delete-jndi-resource

列示外部資源

若要列示外部資源,請鍵入 asadmin list-jndi-resources 指令並指定 JNDI 名稱。例如,鍵入以下指令可以列示外部資源:

$asadmin list-jndi-resources --user adminuser --host plum jndi_name_test

如需完整的環境,請鍵入 asadmin help list-jndi-resources