我写了一个Java程序来连接到Websphere MQ来发布消息.我在Websphere MQ Explore中创建了JNDI名称空间,连接工厂,目标和队列管理器.当我运行我的程序时,它显示ClassCastException从类型转换string到ConnectionFactory.
这是我的代码.任何人都可以帮助解决此问题.
JNDIUtil.java
package com.tradefinance.jms.util;
//JMS classes
import javax.jms.JMSException;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
//JNDI classes
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
//Standard Java classes
import java.util.Hashtable;
import java.util.Properties;
/**
*
* A wrapper class for JNDI calls
*
*/
public class JNDIUtil
{
private Context context;
public JNDIUtil(String icf, String url) throws JMSException, NamingException
{
Hashtable environment = new Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY, icf );
environment.put(Context.PROVIDER_URL, url);
context= new InitialContext( environment );
} …Run Code Online (Sandbox Code Playgroud)