Skip to content
Advertisement

Cannot resolve method ‘getBody’ in Message

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

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement