从WAS迁移到自由时,JNDI上下文初始化错误 [英] JNDI Context Initialization error while migration from WAS to liberty

查看:167
本文介绍了从WAS迁移到自由时,JNDI上下文初始化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

未找到 WsnInitialContextFactory 类.Liberty不支持此类,那么如何删除 jndi.properties 默认设置.此属性文件包含 InitialContext 的此类名称.

The WsnInitialContextFactory class not found exception. Liberty does not support this class, then how can I remove jndi.properties default settings. This property file contain this class name for InitialContext.

属性:

INITIAL_CONTEXT_FACTORY = "com.ibm.websphere.naming.WsnInitialContextFactory" 
CC_PROVIDER_URL = "iiop://localhost.svr.us.xxxxxxx.net:41516"

InitialContext 查找:

   try {
        Hashtable params = new Hashtable();
        params.put(Context.INITIAL_CONTEXT_FACTORY, ADProperties.WS_INITIAL_CONTEXT_FACTORY);
        params.put(Context.PROVIDER_URL, ADProperties.AD_PROVIDER_URL);

        Context ctx = new InitialContext(params);
        try {
            ds = (DataSource) ctx.lookup("java:comp/env/" + jndiName);
        } catch (Exception ex) {
            LogUtil.debugException("DBConnectionManager", "Exception in init: Resource reference DataSource lookup Error.", "init()", ex, "");
            try {
                ds = (DataSource) ctx.lookup("jdbc/" + jndiName);
            } catch (Exception exp) {
                LogUtil.debugException("DBConnectionManager", "Exception in init: Datasource lookup Error.", "init()", exp, "");
            }
        }

例外:

[INFO] [err] java.lang.NoClassDefFoundError: Could not initialize class com.ibm.websphere.naming.WsnInitialContextFactory
[INFO] [err]    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[INFO] [err]    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[INFO] [err]    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[INFO] [err]    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
[INFO] [err]    at com.ibm.ws.jndi.internal.WASInitialContextFactoryBuilder.createInitialContextFactory(WASInitialContextFactoryBuilder.java:57)
[INFO] [err]    at [internal classes]
[INFO] [err]    at java.naming/javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:730)
[INFO] [err]    at java.naming/javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)
[INFO] [err]    at java.naming/javax.naming.InitialContext.init(InitialContext.java:236)
[INFO] [err]    at java.naming/javax.naming.InitialContext.<init>(InitialContext.java:184)

推荐答案

自由不支持WsnInitialContextFactory类.您可以做到这一点(它也可以在传统的WebSphere中工作):

Liberty does not support the WsnInitialContextFactory class. You can just do this (and it'll work in WebSphere traditional as well):

try {
    Context ctx = new InitialContext(new Hashtable());
    try {
        ds = (DataSource) ctx.lookup("java:comp/env/" + jndiName);
    } catch (Exception ex) {
        LogUtil.debugException("DBConnectionManager", "Exception in init: Resource reference DataSource lookup Error.", "init()", ex, "");
        try {
            ds = (DataSource) ctx.lookup("jdbc/" + jndiName);
        } catch (Exception exp) {
            LogUtil.debugException("DBConnectionManager", "Exception in init: Datasource lookup Error.", "init()", exp, "");
        }
    }

这篇关于从WAS迁移到自由时,JNDI上下文初始化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆