gpt4 book ai didi

websphere-liberty - 在 Liberty Profile 中配置不是数据源的 JNDI 资源

转载 作者:行者123 更新时间:2023-12-04 02:49:26 35 4
gpt4 key购买 nike

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

非常感谢

最佳答案

您可以使用 server.xml 中的元素配置它。这记录在 infocenter 中.本质上,您可以使用以下命令在 server.xml 中启用 jndi 功能:

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

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

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

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

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

你从 JNDI 得到一个数字。如果你这样表达:

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

你得到一个双倍。

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

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

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

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

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

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

然后使用此代码查找:

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

关于websphere-liberty - 在 Liberty Profile 中配置不是数据源的 JNDI 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18083341/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com