请勿使用特定于 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 传统文件中使用的值:

以下示例说明了在迁移到 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 的自动修复后,代码将迁移到如图所示的位置:


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);
}

注意: 自动修复将对所有 t3 URL(包括 SSL ' t3s:// ' URL)使用默认引导端口 2809。 请检查服务器设置,以确保将正确的端口用于每个 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:" + 端口);

InitialContext ctx = new InitialContext(ht);
}

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

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

.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 属性值规则。