[jboss-user] [Tomcat, HTTPD, Servlets & JSP] - java.lang.ClassCastException: javax.naming.Reference

chandara do-not-reply at jboss.com
Mon Oct 2 06:36:54 EDT 2006


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.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3975452#3975452

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3975452



More information about the jboss-user mailing list