0

I’m quite new in JavaEE and trying to deal with JMS stuff. Here is the MessageBean that implement MessageListener and Override onMessage where I consequently try to receive message from Queue My code snippet:

@Override
public void onMessage(Message message) {
 try{
  System.out.println(message.getBody(String.class));
 }catch(JMSException e){
   System.err.println(e.toString());
 }
}

But unfortunately there is an compiling error that method getBody cannot be resolved and marked as red in IntelliJ. Help me figure out. Thanks in advance

Gipsy King
  • 186
  • 2
  • 2
  • 14
  • 1
    What package of Message? – Rony Nguyen Sep 13 '20 at 17:52
  • @ToànNguyễnHải onMessage is method from interface MessageListener. But Object that sends message is JMSProducer which is from java.jms package – Gipsy King Sep 13 '20 at 18:18
  • share your pom.xml. I prefer you should read the tutorial of spring-jms https://github.com/spring-guides/gs-messaging-jms first – Rony Nguyen Sep 13 '20 at 18:30
  • @ToànNguyễnHải I don’t use Spring I use EJB and MessageBean... I’ve just started studying EE and try to figure out how to work with EJB – Gipsy King Sep 13 '20 at 18:41

1 Answers1

2

The method getBody(Class<T> c) is new in JMS 2.0. Your project is almost certainly including the JMS 1.1 specification jar. Change your project so you include the JMS 2.0 specification jar instead and that error should go away.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43