微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

JavaEE MDB“EJB 容器初始化错误”

如何解决JavaEE MDB“EJB 容器初始化错误”

我对 JavaEE 还很陌生,我想制作一个消息驱动的 bean,它使用一条消息和一个产生消息的生产者。我从 JavaEE 手册中获得了大部分代码,但它不想在我的 Glassfish 服务器上编译。

这是 MDB 的代码

<router-link
  v-for="group in course.groups.slice(0,6)"
  :key="group.id"
  :to=" status == 'unregistered' ? { name: 'login',query: { next: $route.name }} : '' "
>
  <button
     v-b-modal="status == 'unregistered' ? '' : 'group_detail_modal' "
     @click="getCourseDetail(group,(group_id = group.id))"
     >
    Click
  </button>
</router-link>

<b-modal
  :title="group_detail.level"
  id="group_detail_modal"
  body-class="biginermodal"
  hide-footer
  centered
  size="lg"
>
<!-- content -->
</b-modal>

<script>

  created() {
    this.getCourseDetail();
  },getCourseDetail(group,group_id) {
  if (this.$route.query.courseId === group_id) {
    this.group_detail = group;
  } else {
    alert("no");
  }
},data() {
    return {
      group_detail: { title: "",level: "" }
    };
  },</script>

以及生产者的代码

    @MessageDriven(activationConfig = {
        @ActivationConfigProperty(
                propertyName = "destination",propertyValue = "myQueue"),@ActivationConfigProperty(
                propertyName = "destinationType",propertyValue = "javax.jms.Queue")
    })
    public class MessageDrivenBean implements MessageListener {
        public MessageDrivenBean() {

    }

    @Override
    public void onMessage(Message message) {
        try {
            System.out.println("Message received: " + message.getBody(String.class));
        } catch (JMSException e) {
            e.printstacktrace();
        }
    }
}

“send()”方法在另一个 EJB 中被调用。 但是当我运行 glassfish 服务器时,代码无法编译并且有很多警告,但我可以从中读取到“EJB 容器初始化错误”。有人知道怎么处理吗?

谢谢!

PS:部分错误

    @Stateless
    public class MsgProducer {
    public MsgProducer() {

    }

    public void send() {
        try {
            // Gets the JNDI context
            System.out.println("In the producer");
            InitialContext jndiContext = new InitialContext();
            // Looks up the administered objects
            ConnectionFactory connectionFactory = (ConnectionFactory) jndiContext.lookup("jms/myConnectionFactory");
            Destination queue = (Destination) jndiContext.lookup("jms/myQueue");
            // Creates the needed artifacts to connect to the queue
            Connection connection = connectionFactory.createConnection();
            Session session = connection.createSession(false,Session.AUTO_ACKNowLEDGE);
            MessageProducer producer = session.createProducer(queue);
            // Sends a text message to the queue
            TextMessage message = session.createTextMessage("Text message sent at " + new Date());
            producer.send(message);
            connection.close();
        } catch (Exception e) {
            e.printstacktrace();
        }
    }
}

解决方法

解决了!问题是我的 propertyValue 是 javax.jms.Queue 而我需要 jakarta.jms.Queue。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。