我正致力于将现有的EJB应用程序从Jersey 1.x迁移到2.x.面临与EJB和JMS队列概念相关的许多挑战。执行以下代码时,我面临Null指针异常。
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSession;
public class SessionImpl implements SessionLocal {
@Resource(mappedName = "java:/RemoteJmsXA")
private QueueConnectionFactory queueConnectionFactory;
@Inject
private ConvRequestSessionLocal convRequestSession;
private RequestSessionLocal asyncSession;
@PostConstruct
public void initialize() {
QueueConnection connection = null;
QueueSession queueSession = null;
try {
connection = queueConnectionFactory.createQueueConnection();
queueSession = connection.createQueueSession(true, QueueSession.SESSION_TRANSACTED);
asyncSession = AsyncUtils.mixinAsync(convRequestSession);
} catch (JMSException e) {
LOG.error("Error ocurred while connecting to remote queues. " + e.getLocalizedMessage());
throw new RuntimeException("Error occured while connecting to remote queues.", e);
} finally {
try {
if (queueSession != null) {
queueSession.close();
}
if (connection != null) {
connection.close();
}
} catch (JMSException e) {
LOG.error("Error occured while closing connection to remote queues. " + e.getLocalizedMessage());
}
}
}
}
例外:
2017-01-18 20:08:44,317 WARNING [org.glassfish.jersey.internal.Errors] (http-127.0.0.1-8080-4) The following warnings have been detected: WARNING: Unknown HK2 failure detected:
MultiException stack 1 of 2
java.lang.NullPointerException
at com.ejb.session.impl.SessionImpl.initialize(SessionImpl.java:809)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
堆栈跟踪显示异常完全抛出此行 connection = queueConnectionFactory.createQueueConnection();