无法解决 Message 中的 ‘getBody’ 方法。

huangapple go评论59阅读模式
英文:

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&lt;T&gt; 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.

huangapple
  • 本文由 发表于 2020年9月14日 01:46:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/63873820.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定