如何设置Context.INITIAL_CONTEXT_FACTORY? NoInitialContextException? [英] How to set Context.INITIAL_CONTEXT_FACTORY? NoInitialContextException?

查看:1407
本文介绍了如何设置Context.INITIAL_CONTEXT_FACTORY? NoInitialContextException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JMS和Websphere服务器的新手,我正在尝试从我的Java代码访问在Websphere Application Server 8上配置的JMS队列。我无法准确理解应为Context.INITIAL_CONTEXT_FACTORY设置什么值。它应该是类的完全限定类名还是特定于应用程序服务器的东西?

I am new to JMS and the Websphere server and I am trying to access a JMS queue configured on Websphere Application Server 8 from my Java code. I am not able to understand exactly what value should be set for Context.INITIAL_CONTEXT_FACTORY. Should it be the fully qualified class name of the class or something specific to the application server?

Hashtable environment = new Hashtable();
        environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
        environment.put(Context.PROVIDER_URL, "iiop://localhost:9081");

将Context.INITIAL_CONTEXT_FACTORY的值设置为完全限定的类名,即com.ms.test.Demo I我收到NoInitialContextException。

On setting value for Context.INITIAL_CONTEXT_FACTORY as fully qualified class name i.e com.ms.test.Demo I am receiving NoInitialContextException.

PFB我正在使用的代码 -

PFB the code that I am using -

package com.jms.test;

import java.util.Hashtable;
import javax.jms.Queue;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class Demo {
  public static void main(String[] args) throws NamingException {
        System.out.println("Start.....");
        Hashtable environment = new Hashtable();
        environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.jms.test.Demo");
        environment.put(Context.PROVIDER_URL, "iiop://localhost:9081");
       //String pUrl = System.getProperty(Context.PROVIDER_URL);
        //System.out.println("*******"+pUrl+"********");
        InitialContext ctx = new InitialContext(environment);
        Queue queue = (Queue) ctx.lookup("jms/TestQ111200");
        System.out.println("*** Queue is *** "+queue.toString());
  }}

我使用上面给出的步骤在Websphere Application Server中进行了JMS配置以下链接:
http://pic.dhe.ibm.com/infocenter/iisinfsv/v8r1/index.jsp?topic=/com.ibm.swg.im.iis .infoservdir.user.doc / topics / t_isd_user_setting_up_jms_in_was.html

I have made JMS configurations in the Websphere Application Server using the steps given at the link below: http://pic.dhe.ibm.com/infocenter/iisinfsv/v8r1/index.jsp?topic=/com.ibm.swg.im.iis.infoservdir.user.doc/topics/t_isd_user_setting_up_jms_in_was.html

推荐答案

连接时总是使用以下内容WebSphere,而不是您自己的类。

You always use the following, when connecting to WebSphere, not your own class.

environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");

需要正确连接到WAS。
对于第二个属性,您需要提供bootstrap端口而不是http。通常它是 2809 ,在 SystemOut.log 中查找以下消息:

It is required to correctly connect to WAS. For the second property you need to provide bootstrap port not http. Usually it is 2809, look for the following message in SystemOut.log:

00000001 NameServerImp A   NMSV0018I: Name server available on bootstrap port 2809.

您还需要特定的罐子,以便客户连接到WAS JMS。请参阅
使用WebSphere Application Server安装和配置JMS瘦客户机

You will also need specific jars for your client to connect to WAS JMS. See Installing and configuring the Thin Client for JMS with WebSphere Application Server

这篇关于如何设置Context.INITIAL_CONTEXT_FACTORY? NoInitialContextException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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