0

我们正在将我们的代码从 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 属性,或者如果不需要这些属性,则删除该文件。

有人可以帮助我们如何使用 default 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);
        }
    }
}
4

1 回答 1

0

InitialContext在此调用中使用默认值:

ctx = new InitialContext();

所以你只需jndi.properties要从放置它的任何地方移除。

非默认上下文如下所示:

Hashtable env = new Hashtable();
... setting env properties
... creating non def context
ctx = new InitialContext(env);
于 2018-06-04T12:12:16.890 回答