请勿使用特定于 WebLogic 的 JNDI 属性值或 t3 协议

您必须移除或替换在获取应用程序中 IntialContext 时使用的特定于 WebLogic 的命名属性。 迁移工具扫描 Java、XML 和属性文件以查找属性值:weblogic.jndi.WLInitialContextFactoryt3://.*t3s://*。 例如,如果应用程序指定以下属性,那么工具将标记红色文本:

Liberty

Java 文件

将应用程序移到 Liberty 时,请勿在传递给 InitialContext 构造函数的属性中指定初始上下文工厂或提供程序 URL。 除非在设置其他命名属性,否则请使用空构造函数。

以下示例说明了在迁移到 Liberty 时该规则将标记的应用程序代码:


import java.util.Hashtable;
import javax.naming.InitialContext;
...
void main( String[] args ) {
Hashtable ht = new Hashtable();

ht.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
ht.put("java.naming.provider.url", "t3://localhost:7001");

InitialContext ctx = new InitialContext(ht);
}

手动移除不必要的属性:


import javax.naming.InitialContext;
...
void main( String[] args ) {
InitialContext ctx = new InitialContext();
}

XML 文件

除了标记 java 文件,工具还将标记包含 WebLogic 属性值的 xml 文件。对于 Liberty,应移除这些属性以使用缺省 InitialContext 初始化值。

属性文件

除了标记 java 和 xml 文件,工具还将标记包含 WebLogic 属性值的属性文件。对于 Liberty,应移除这些属性。

WebSphere Application Server Traditional

Java 文件

在迁移到 WebSphere Application Server Traditional 时,将标记前述相同的 WebLogic 属性。 在源扫描程序中,存在针对 Java 文件的快速修订,它用于将 WebLogic 命名属性值更改为在 WebSphere Application Server Traditional 中有效的值:

以下示例说明了在迁移到 WebSphere Application Server Traditional 时该规则将标记的应用程序代码:


import java.util.Hashtable;
import javax.naming.InitialContext;
...
void main( String[] args ) {
Hashtable ht = new Hashtable();

ht.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
ht.put("java.naming.provider.url", "t3s://localhost:7001");

InitialContext ctx = new InitialContext(ht);
}

使用先前显示的相同示例,运行针对 WebSphere Application Server Traditional 的 Java 快速修订之后,将按如下方式迁移代码:


import java.util.Hashtable;;
import javax.naming.InitialContext;;

...

void main( String[] args ) {
Hashtable ht = new Hashtable();

ht.put("java.naming.factory.initial", "com.ibm.websphere.naming.WsnInitialContextFactory");
ht.put("java.naming.provider.url", "corbaloc:iiop:localhost:2809");

InitialContext ctx = new InitialContext(ht);
}

注:快速修订将缺省引导程序端口 2809 用于所有 t3 URL,包括 SSL“t3s://”URL。 请检查服务器设置,以确保将正确的端口用于每个 URL。 有关其他信息,请参阅 Port Number Settings for WebSphere Application Server traditional 一文。

在移至 WebSphere Application Server Traditional 时的另一个选项是移除属性并使用空的 InitialContext() 构造函数。

警告:快速修订仅会调整字面值。 如果正在使用变量来构建 URL,那么将必须手动迁移该 URL。

快速修订之前的变量示例:

void main( String[] args ) {
Hashtable ht = new Hashtable();

...

String port = "7001";
ht.put("java.naming.provider.url", "t3://localhost:" + port);

InitialContext ctx = new InitialContext(ht);
}

快速修订之后的变量示例:

void main( String[] args ) {
Hashtable ht = new Hashtable();

...

String port = "7001";
ht.put("java.naming.provider.url", "corbaloc:iiop:localhost:" + port);

InitialContext ctx = new InitialContext(ht);
}

请注意,字符串变量 port 未更改。 请确保所有此类变量都已迁移。

以下示例对应用于 XML 代码的类似更改进行了说明。

运行快速修订之前的 XML 代码:

<property name="java.naming.factory.initial" value="weblogic.jndi.WLInitialContextFactory"/>

<property name="java.naming.provider.url" value="t3://localhost:7001/"/>

运行快速修订之后的 XML 代码:

<property name="java.naming.factory.initial" value="com.ibm.websphere.naming.WsnInitialContextFactory"/>

<property name="java.naming.provider.url" value="corbaloc:iiop:localhost:2809/"/>

属性文件

当迁移工具检查属性文件时,快速修复不会迁移命名工厂和提供程序属性。对于 WebSphere Application Server Traditional,请移除这些属性或将其更改为 WebSphere 命名属性值。

另请参阅使用可移植 JNDI 属性值规则。