我们正在将代码从WAS 8.0迁移到Liberty 17.0.0.1版本。当我们尝试测试应用程序在线功能时,我们收到以下错误,
java.lang.ClassNotFoundException:
com.ibm.websphere.naming.WsnInitialContextFactory
com.ibm.ws.jndi.internal.WASInitialContextFactoryBuilder
我们还使用Liberty Migration工具包检查了我们的ear文件,我们在其中一个jar中遇到了严重问题,
迁移到Liberty时,请使用java.naming.factory.initial和java.naming.provider.url JNDI属性的默认值。以下WebSphere Application Server传统值对于这些属性无效:
java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory
java.naming.provider.url=corbaloc:iiop:localhost:2809
使用InitialContext(Hashtable)构造函数时,请删除这两个属性。如果没有使用其他属性,则可以使用默认构造函数。
如果属性文件规则检测到jndi.properties文件,请检查文件中的属性。删除java.naming.factory.initial和java.naming.provider.url属性,或者如果不需要任何属性,则删除该文件。
有人可以帮助我们使用默认InitialContext
。请找到调用jndi和上下文路径的附加代码,
import java.util.HashMap;
import java.util.Map;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* @class name JndiObjectLocator.java
* @author pkannan
* @creation date Nov 1, 2004
* @description
*/
public class JndiObjectLocator {
/** Intial context to the JNDI Tree */
private InitialContext ctx = null;
/** Object Cache */
private Map cache = null;
//Object used to log messages
private static final IBwLog bwLog =
BwLogFactory.create(BwLogUtil.getClassName());
/**
* Creates a new JndiObjectLocator object.
*
* @throws BOBRuntimeException When Initial Context creation fails.
*/
public JndiObjectLocator() throws BOBNestedRuntimeException {
cache = new HashMap();
try {
ctx = new InitialContext();
System.out.println("CTX:" +ctx);
} catch (NamingException ne) {
bwLog.error(EVENTS.INITIALIZE, "Context Initialization Failure"+BwLogUtil.stackToStr(ne));
throw new BOBNestedRuntimeException(
"Context Initialization Failure",
ne);
}
}
/**
* Fetches any Object bound in JNDI.
*
* @param jndiName JNDI Name of the Object to be retrieved.
*
* @return Object bound to the given JNDI name.
*
* @throws ObjectLookUpException When JNDI lookup fails for any reason.
*/
public Object fetch(String jndiName) throws ObjectLookUpException {
Object obj = cache.get(jndiName);
System.out.println("JNDI:" +jndiName);
if (obj == null) {
try {
if (ctx != null) {
obj = ctx.lookup(jndiName);
if (obj != null && cache.get(jndiName) == null) {
synchronized (cache) {
cache.put(jndiName, obj);
}
}
} else {
bwLog.error(
EVENTS.INITIALIZE,
"Context Initialization Failure");
throw new BOBRuntimeException("Context Initialization Failure");
}
} catch (NamingException ne) {
bwLog.error(
EVENTS.JNDI_LOOKUP,
"Context Initialization Failure"+BwLogUtil.stackToStr(ne));
throw new ObjectLookUpException(
"BOB DataSource Lookup Failure",
ne);
}
}
return obj;
}
/**
* Closes the JNDI context.
*
* @throws BOBRuntimeException When IntialContext fails to close.
*/
public void destroy() throws BOBNestedRuntimeException {
try {
ctx.close();
} catch (NamingException ne) {
bwLog.error(EVENTS.INITIALIZE, "Naming Context Closing Exception"+BwLogUtil.stackToStr(ne));
throw new BOBNestedRuntimeException(
"Naming Context Closing Exception",
ne);
}
}
}
答案 0 :(得分:0)
您在此次通话中使用默认InitialContext
:
ctx = new InitialContext();
因此您只需要从放置的任何位置删除jndi.properties
。
非默认上下文如下所示:
Hashtable env = new Hashtable();
... setting env properties
... creating non def context
ctx = new InitialContext(env);