注入JMS @Resource时,Glassfish中的NullPointer [英] NullPointer in Glassfish when inject JMS @Resource
问题描述
在类中发送消息我有以下几点:$ b
$ b
@Resource(mappedName =jms / MyConnectionFactory)
public static QueueConnectionFactory factory;
@Resource(mappedName =jms / MyQueue)
公共静态队列队列;
这导致了一个NullPointer,我第一次尝试访问工厂。如果我尝试使用JNDI查找对象,它就会起作用。这个类只是一个简单的Web应用程序中运行的JSP访问的POJO。
是因为它是POJO而不是,例如,这是失败的servlet?
我曾假设它在Glassfish内部署和运行的事实就足够了 - 显然我错了......
mappedName
。 name
是JNDI名称, mappedName
是别的。请参阅 API文档 @Resource(name =jms / MyConnectionFactory)
public static QueueConnectionFactory factory;
我刚刚读到你的课是一个简单的POJO。您的类必须是某个由容器管理的bean,才能使这些注释生效。像@Stateless,@Stateful,@Singleton一样。
I'm trying to write a very simple JMS app to deploy on Glassfish as a means of getting my head around JMS.
In the class the sends the message I have the following:
@Resource(mappedName="jms/MyConnectionFactory")
public static QueueConnectionFactory factory;
@Resource(mappedName="jms/MyQueue")
public static Queue queue;
This results in a NullPointer, the first time I try and access the factory. If I try and look up the object using JNDI, however, it works. This class is simply a POJO which is accessed by a JSP running in a simple web app.
Is it because it is a POJO and not, for example, a servlet that this is failing?
I had assumed that the fact it was deployed and running inside Glassfish would be enough - obviously I am wrong...
Use name
instead of mappedName
. name
is the JNDI name, mappedName
is something else. See the API doc
@Resource(name="jms/MyConnectionFactory")
public static QueueConnectionFactory factory;
I just read that your class is a simple POJO. Your class must be some bean that is managed by a container in order to make these annotations work. Like @Stateless, @Stateful, @Singleton.
这篇关于注入JMS @Resource时,Glassfish中的NullPointer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!