JMSContext NullPointer异常-Wildfly 8.2.0默认队列 [英] JMSContext NullPointer Exception - wildfly 8.2.0 default queue

查看:151
本文介绍了JMSContext NullPointer异常-Wildfly 8.2.0默认队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Wildfly中将消息发送到我的默认队列,当我调用"sendMessage()"时,JMSContext给了我一个空指针异常.我该如何解决?

I am trying to send messages to my default queue in wildfly and when i invoke "sendMessage()" the JMSContext is giving me a null pointer exception. what can i fix ?

public class SendMsg {


@Resource(lookup = "java:/ConnectionFactory")
 ConnectionFactory connectionFactory;


JMSContext context=connectionFactory.createContext();

@Resource(mappedName="java:/jms/queue/test")
Queue queue;

public void sendMessage(String message) {
    System.out.println("fancy beans");
    context.createProducer().send(queue, message);
}

}

推荐答案

您不能将连接工厂称为早期".在构建bean期间不会注入它.直接注入JMSContext可能会更容易.

You cant call the connection factory that "early". It will not be injected during the construction of your bean. Inject a JMSContext directly is probably easier.

public class SendMsg {


//@Resource(lookup = "java:/ConnectionFactory")
//ConnectionFactory connectionFactory;

@Inject
JMSContext context;   //=connectionFactory.createContext();

这篇关于JMSContext NullPointer异常-Wildfly 8.2.0默认队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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