在 Liberty Profile 中配置不是数据源的 JNDI 资源 [英] Configuring a JNDI resource that isn't a datasource in Liberty Profile

查看:46
本文介绍了在 Liberty Profile 中配置不是数据源的 JNDI 资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Liberty Profile 中运行现有的 WebSphere 应用程序,但遇到了问题.该应用程序在服务器中配置了一个资源环境条目,我需要将其转换为 Liberty Profile 资源.如何在 server.xml 中配置 JNDI 资源,该资源不是数据源 (dataSource) 或常量 (jndiEntry)?

I'm trying to run an existing WebSphere application in Liberty Profile but have run into a problem. The application has a resource environment entry configured in the server which I need to translate into a Liberty Profile resource. How can I configure a JNDI resource in the server.xml, that isn't a datasource (dataSource) or a constant (jndiEntry)?

非常感谢

推荐答案

您可以使用 server.xml 中的元素进行配置.这记录在 信息中心.本质上,您可以使用以下命令在 server.xml 中启用 jndi 功能:

You can configure this using the element in the server.xml. This is documented in the infocenter. Essentially you enable the jndi feature in the server.xml using this:

<featureManager>
   <feature>jndi-1.0</feature>
</featureManager>

然后您可以配置 JNDI 条目.你只能使用它来做简单的类型,所以没有复杂的对象.要配置您的条目,请执行以下操作:

Then you can configure the JNDI entries. You can only do simple types using this, so no complex objects. To configure your entry you then do this:

<jndiEntry jndiName="myProp/philosopher" value="plato" />

Liberty 配置文件进行类型推断,因此如果您表达了这一点:

The Liberty profile does type inference, so if you expressed this:

<jndiEntry jndiName="myProp/philosopher" value="1234" />

您从 JNDI 获得一个数字.如果你表达这个:

you get an Number from JNDI. If you express this:

<jndiEntry jndiName="myProp/philosopher" value="1234.3D" />

你得到一个双人.

如果你想要一个数字作为字符串文字,你可以用引号来表达它:

If you want a number as a string literal you would express it using quotes:

<jndiEntry jndiName="myProp/philosopher" value='"1234.3D"' />

要从您的应用程序中获取此信息,您可以进行全局查找,例如:

To get this from your application you can do a global lookup such as:

Context ctx = new InitialContext();
Object jndiConstant = ctx.lookup("myProp/philosopher");
String philosopher = (String) jndiConstant;

您还可以将其映射到 ibm-web-bnd.xml 文件中的资源环境条目:

You can also map this to a resource environment entry in the ibm-web-bnd.xml file:

<env-entry name="philosopher" binding-name="myProp/philosopher" />

然后使用此代码查找:

Context ctx = new InitialContext();
Object jndiConstant = ctx.lookup("java:comp/env/philosopher");
String philosopher = (String) jndiConstant;

这篇关于在 Liberty Profile 中配置不是数据源的 JNDI 资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆