-1

I'm pretty new to JavaEE, and I want to make a message driven bean that consumes a message and a producer that produces a message. I got most of this code from a JavaEE manual, but it doesn't want to compile on my Glassfish server.

Here is the code for the MDB:

    @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();
        }
    }
}

And the code for the producer:

    @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();
        }
    }
}

The method "send()" is called in another EJB. But when I run the glassfish server the code doesn't compile and with a lot of warnings but what I can read from it is "EJB Container initialisation error". Does anybody know what to do with it?

Thank you!

PS: part of the error:

java.lang.RuntimeException: EJB Container initialization error
    at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:210)
    at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:267)
    at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:75)
java.lang.RuntimeException: EJB Container initialization error
    at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:210)
    at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:267)
    at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:75)
  Exception while loading the app : EJB Container initialization error
java.lang.Exception
    at com.sun.enterprise.connectors.inbound.ConnectorMessageBeanClient.setup(ConnectorMessageBeanClient.java:189)
    at org.glassfish.ejb.mdb.MessageBeanContainer.<init>(MessageBeanContainer.java:227)
    at org.glassfish.ejb.mdb.MessageBeanContainerFactory.createContainer(MessageBeanContainerFactory.java:39)
    at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:198)
    at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:267)
    at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:75)
invzbl3
  • 5,872
  • 9
  • 36
  • 76
jimjim
  • 19
  • 2

1 Answers1

0

Solved it! The problem was that my propertyValue was javax.jms.Queue while I needed jakarta.jms.Queue.

jimjim
  • 19
  • 2