在應用程式中取得 IntialContext 時,必須移除或取代所使用的 WebLogic 專用命名內容。
移轉工具會掃描 Java、XML 及內容檔來找出下列內容值:weblogic.jndi.WLInitialContextFactory、t3://.* 及 t3s://*。
例如,如果應用程式指定下列內容,該工具會標示紅色文字:
- java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
- java.naming.provider.url=t3://localhost:7001
- java.naming.provider.url=t3s://localhost:7001
Liberty
Java 檔
將應用程式移至 Liberty 時,請勿在傳遞至 InitialContext 建構子的內容中指定起始環境定義 Factory 或提供者 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 傳統中使用的值:
- java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory
- java.naming.provider.url=corbaloc:iiop:localhost:2809
下例範例說明在移轉至 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 使用正確的埠。 如需相關資訊,請參閱 WebSphere Application Server Traditional 的埠號設定文章。
移至 WebSphere Application Server Traditional 時的另一個選項,是移除這些內容並使用空的 InitialContext() 建構子。
警告 :自動修正只會調整字面意義。 如果 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 程式碼的類似變更。
<property name="java.naming.factory.initial"
value="weblogic.jndi.WLInitialContextFactory"/>
<property name="java.naming.provider.url"
value="t3://localhost:7001/"/>
<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 內容值規則。