JMS ConnectionFactory NullPointerException

I am trying to run a tutorial with JMS and I have a problem. I am using the latest version of Glassfish with the latest JavaEE SDK. I create a ConnectionFactory resource in the Glassfish admin console, and then try to create it in code using the following call:

 @Resource(mappedName = "jms/ExampleConnectionFactory") private static ConnectionFactory connectionFactory; 

But I get a NullPointerException in the following line:

 Connection connection = connectionFactory.createConnection(); 

How can I solve this problem? Thanks in advance.

+4
source share
3 answers

I had this problem too, trying to get a RESTful web service to post a message to the JMS queue.

For me, I followed this guide here ( http://www.tricoder.net/blog/?p=128 ), and I needed to put the @Stateless over my public class... code.

For some reason (I don't know why, since I'm completely new to this), dependency requires @Stateless . (He says in the source above)

EDIT: Even so, when developing my application, I sometimes had a NullPointerException . Restarting Glassfish fixes the problem when this happens.

0
source

JMS Consumer,

Try adding the @Stateless to your class and add the javax.ejb.Stateless package javax.ejb.Stateless .

I hope you find this helpful.

0
source

You need to do 2 things:

  • Specify properties for InitialContext:

    Properties props = new Properties (); props.setProperty (Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory"); Context initialContext = new InitialContext (props);

  • Add the library to your project (adjust the path):

C:\installs\glassfish\glassfish-4.1\glassfish\lib\gf-client.jar

0
source

Source: https://habr.com/ru/post/1391593/


All Articles