已创建并部署 MDB 项目,但无法从独立程序执行查找



我已经创建了一个MDBbean并部署在glassfish 4中,并且应用程序已成功部署,但是我正在尝试使用独立客户端将消息放入队列中。我收到此错误。

**java.lang.NullPointerException at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:347( javax.naming.NamingException: Lookup failed for 'jms/myQueue' in SerialContext[myEnv={java.naming.provider.url=iiop://localhost:3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [根异常是javax.naming.NamingException: 无法获取SerialContextProvider for SerialContext[myEnv={java.naming.provider.url=iiop://localhost:3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}[根异常是java.lang.NullPointerException]]

原因:javax.naming.NamingException: 无法获取 SerialContextProvider for SerialContext[myEnv={java.naming.provider.url=iiop://localhost:3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is java.lang.NullPointerException]**

MDB 类代码为:

package test;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "jms/myQueue")
,
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
,
@ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "jms/myConnectionFactory")
})
public class testMDB1 implements MessageListener {
public testMDB1() {
}
@Override
public void onMessage(Message message) {
if (message instanceof TextMessage) {
TextMessage t = (TextMessage) message;
try {
System.out.println("ye le " + t.getText());
} catch (JMSException ex) {
Logger.getLogger(TestMDB.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}

并且客户端文件是

package test;
import java.util.Properties;
import javax.jms.ConnectionFactory;
import javax.jms.JMSContext;
import javax.jms.JMSProducer;
import javax.jms.Queue;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class TestClient {
public static void main(String[] args) {
try {
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
env.put(Context.URL_PKG_PREFIXES, "com.sun.enterprise.naming");
env.put(Context.PROVIDER_URL, "iiop://localhost:3700");
Context remoteContext = new InitialContext(env);
System.out.println("remote context" + remoteContext.getEnvironment());
Queue queue = (Queue) remoteContext.lookup("jms/myQueue");
JMSContext jmsContext = ((ConnectionFactory) remoteContext.lookup("jms/myConnectionFactory")).createContext();
JMSProducer producer = jmsContext.createProducer();
producer.send(queue, "hello ");
System.out.println("1. Sent TextMessage to the Queue");
} catch (NamingException e) {
e.printStackTrace();
}
}
}

我已经添加了gf-client.jar,orb-iiop.jar和appserv-rt.jar但没有什么能解决我的问题。

我开始知道 glassfish 4.1 存在本地客户端无法连接到 MDB 的错误。我在两个 ejb 项目中尝试了相同的方法,它工作得很好。

最新更新