Andres Olarte
Andres Olarte

Reputation: 4380

ClassNotFoundException first time Message Driven Bean is invoked in Weblogic

I have the following simple Message Driven Bean :

@MessageDriven( mappedName ="jms/priceQueue")
public class PriceMessageBean implements MessageListener {
    private Logger logger = Logger.getLogger(
            PriceMessageBean.class.getCanonicalName());

    @Override
    public void onMessage(Message message) {
        logger.info("Message");
        try {
            PriceUpdate update = (PriceUpdate) (((ObjectMessage)message).getObject());
            logger.info("Size: " + update.getPreciousList().size());
        } catch (JMSException jms) {
            logger.info("Error: " + jms.getMessage());
        }
    }
}

It works as expected. However, the first time it receives a message, I get the following exception. It seems that weblogic is trying to load class with the same name as the EJB. If I set a different name (using name="myMDB") weblogic tries to load a class named "myMDB". Any ideas on how to avoid this exception?

java.lang.ClassNotFoundException: PriceMessageBean
    at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:297)
    at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:270)
    at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:64)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:179)
    at weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:43)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:270)
    at com.oracle.injection.provider.weld.WeldBeanManager.newBeanInstance(WeldBeanManager.java:116)
    at com.oracle.injection.provider.weld.WeldWebWithEjbBeanManager.newBeanInstance(WeldWebWithEjbBeanManager.java:30)
    at weblogic.ejb.container.injection.InjectionBasedEjbComponentCreator.getBean(InjectionBasedEjbComponentCreator.java:75)
    at weblogic.ejb.container.manager.BaseEJBManager.createNewBeanInstance(BaseEJBManager.java:209)
    at weblogic.ejb.container.manager.BaseEJBManager.allocateBean(BaseEJBManager.java:235)
    at weblogic.ejb.container.manager.MessageDrivenManager.createBean(MessageDrivenManager.java:280)
    at weblogic.ejb.container.pool.MessageDrivenPool.createBean(MessageDrivenPool.java:169)
    at weblogic.ejb.container.pool.MessageDrivenPool.getBean(MessageDrivenPool.java:92)
    at weblogic.ejb.container.internal.MDListener.execute(MDListener.java:553)
    at weblogic.ejb.container.internal.MDListener.transactionalOnMessage(MDListener.java:488)
    at weblogic.ejb.container.internal.MDListener.onMessage(MDListener.java:385)
    at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:4659)
    at weblogic.jms.client.JMSSession.execute(JMSSession.java:4345)
    at weblogic.jms.client.JMSSession.executeMessage(JMSSession.java:3821)
    at weblogic.jms.client.JMSSession.access$000(JMSSession.java:115)
    at weblogic.jms.client.JMSSession$UseForRunnable.run(JMSSession.java:5170)
    at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:545)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)

Upvotes: 0

Views: 951

Answers (1)

Micah Tessler
Micah Tessler

Reputation: 70

I ran into the same error and I resolved it by naming my MDB the same as my fully qualified java class.

in your case, this would mean changing the mean name to: com.yourpackagename.PriceMessageBean

@MessageDriven( name="com.yourpackagename.PriceMessageBean", 
                mappedName ="jms/priceQueue")
public class PriceMessageBean implements MessageListener {

Upvotes: 1

Related Questions