3 Replies Latest reply on Apr 13, 2009 12:12 PM by Peter Johnson

    java.lang.ClassCastException: javax.naming.Reference

    Chandara Sang Newbie

      Hello
      I am the new of Message Driven Bean in EJB 3.0. And I try to create a first example of Message Driven Bean in EJB 3.0, but it has an error of:

      java.lang.ClassCastException: javax.naming.Reference
      at MDBTestClient.main(MDBTestClient.java:21)

      My Codes are below:
      MDB.java
      package mdb;

      import javax.ejb.MessageDriven;
      import javax.ejb.ActivationConfigProperty;
      import javax.jms.MessageListener;
      import javax.jms.Message;

      @MessageDriven(activationConfig =
      {
      @ActivationConfigProperty(propertyName="destinationType",
      propertyValue="javax.jms.Queue"),
      @ActivationConfigProperty(propertyName="destination",
      propertyValue="queue/mdb")
      })
      public class MDB implements MessageListener {

      public void onMessage (Message msg) {
      System.out.print("Got Message");
      }

      }

      TestClient
      import java.util.Properties;

      import javax.jms.QueueConnection;
      import javax.jms.QueueSender;
      import javax.jms.QueueSession;
      import javax.jms.Queue;
      import javax.jms.QueueConnectionFactory;
      import javax.jms.TextMessage;
      import javax.naming.InitialContext;

      public class MDBTestClient {
      private static QueueConnectionFactory factory=null;
      //private static Queue queue=null;
      private static QueueConnection cnn=null;
      private static QueueSender sender=null;
      private static QueueSession sess=null;

      public static void main(String args[]) {
      try{
      InitialContext ctx=new InitialContext();
      Queue queue=(javax.jms.Queue)ctx.lookup("queue/mdb");
      factory=(QueueConnectionFactory)ctx.lookup("ConnectionFactory");
      cnn=factory.createQueueConnection();
      sess=cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
      TextMessage txt=sess.createTextMessage("Hello My First MDB");
      txt.setLongProperty("send", System.currentTimeMillis());
      sender=sess.createSender(queue);
      sender.send(txt);
      sess.close();

      }
      catch(Exception e){
      e.printStackTrace();
      }
      }
      }

      please help me on this.
      Thanks all of you in advance.