英文:
Cannot resolve method 'getBody' in Message
问题
我在JavaEE方面还很新,在处理JMS相关的内容。这里是实现了MessageListener接口并重写了onMessage方法的MessageBean,在这个方法中,我尝试从队列接收消息。
我的代码片段:
@Override
public void onMessage(Message message) {
try {
System.out.println(message.getBody(String.class));
} catch (JMSException e) {
System.err.println(e.toString());
}
}
但不幸的是,出现了一个编译错误,提示方法getBody无法解析,在IntelliJ中被标记为红色。请帮我找出问题所在。提前谢谢。
英文:
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
答案1
得分: 2
getBody(Class<T> c)
方法是在JMS 2.0中新增的。您的项目几乎肯定包含了JMS 1.1规范的jar包。请修改您的项目,使用JMS 2.0规范的jar包替代,那个错误应该就会消失。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论