通常,在 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>
在管理控制台的左侧窗格中,为要修改的 JNDI 配置打开 Application Server 实例。
打开“JNDI”并选择“外部资源”。
任何已经创建的外部资源会在右侧窗格中列出。
要创建新的外部资源,单击“New”。
在“JNDI Name”字段中,输入要访问资源的名称。
此名称将登记到 JNDI 命名服务中。
在“资源类型”字段中,输入全限定的类型定义,如上面示例中所示。
“资源类型”定义遵循的格式为 xxx.xxx。
在“NDI 查找”字段中,输入要在外部系统信息库中查找的 JNDI 值。
例如,在创建一个与外部系统信息库连接的外部资源时,为了测试某个 Bean 类,“JNDI 查找”可能会如下所示:cn=testmybean。
在“工厂类”字段中,输入 JNDI 工厂类外部系统信息库(例如 com.sun.jndi.ldap)。
此类实现了 javax.naming.spi.ObjectFactory 接口。
在“说明”字段中,为要创建的资源输入说明。
此说明是字符串值,最多可以包含 250 个字符。
在“其他属性”部分,添加属性名称和值。
选中“已启用外部资源”复选框,将启用外部资源。
单击“确定”以保存外部资源。
如果已在群集或独立实例上部署外部资源,则可以使用“目标”选项卡管理目标。此选项卡将在创建外部资源之后显示。通过输入目标名称并单击“确定”来设置目标。
在管理控制台的左侧窗格中,为要修改的 JNDI 配置打开 Application Server 实例。
打开“JNDI”并选择“外部资源”。
任何已经创建的外部资源会在右侧窗格中列出。
要编辑外部资源,请在右侧窗格中单击文件名。
编辑“资源类型”字段、“JNDI 查找”字段、“工厂类”字段或“说明”字段。
选中“已启用外部资源”复选框,将启用外部资源。
单击“保存”以保存对外部资源的更改。
要列出外部资源,请键入 asadmin list-jndi-resources 命令并指定 JNDI 名称。例如,键入以下命令可以列出外部资源:
$asadmin list-jndi-resources --user adminuser --host plum jndi_name_test
要查看完整的上下文,请键入 asadmin help list-jndi-resources。