I’m trying to run a tutorial with JMS and I have a problem. I’m using the latest Glassfish version with the latest JavaEE SDK. I’m creating a ConnectionFactory resource in the Glassfish admin console and then trying to instantiate it in the code using the following call:
@Resource(mappedName = "jms/ExampleConnectionFactory")
private static ConnectionFactory connectionFactory;
But I’m getting the NullPointerException on the following line:
Connection connection = connectionFactory.createConnection();
How can I solve this problem? Thanks in advance.
I was having this problem as well while attempting to have a RESTful web service place a message onto a JMS queue.
For me, I followed this tutorial here (http://www.tricoder.net/blog/?p=128), and I needed to place an
@Statelessannotation above mypublic class...code.For some reason (I don’t know why, as I am totally new to this) the
@Statelessis required for dependency injection to work. (It says that in the source above)EDIT: Even with that, while developing my app, I would sometimes have the
NullPointerException. Restarting Glassfish fixes the problem when that happens.