I am getting javax.naming.NameNotFoundException while trying to look up TimerManager. Here I am giving MDB components.
MDBTimer.java
package my.examples.mdb.timer;
import javax.ejb.MessageDriven;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import commonj.timers.TimerManager;
@MessageDriven(mappedName = "TEST_Q",name = "MyTimerMDB",activationConfig =
{
@javax.ejb.ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@javax.ejb.ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@javax.ejb.ActivationConfigProperty(propertyName = "transactionType", propertyValue = "Container") })
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class MDBTimer implements MessageListener {
private static TimerManager timerManager = null;
@Override
public void onMessage(Message arg0) {
System.out.println("onMessage() method called...\n\n");
if (arg0 instanceof ObjectMessage) {
ObjectMessage msg = (ObjectMessage) arg0;
try {
if (msg.getObject() instanceof String) {
System.out.println("Message received >> "+msg.getObject());
}
}catch (Exception e){
}
}
if(timerManager==null) {
try {
InitialContext ctx = new InitialContext();
timerManager = (TimerManager)
ctx.lookup("java:comp/env/timer/MyDefaultTimer");
/*timerManager = (TimerManager)
ctx.lookup("timer/MyDefaultTimer");*/
} catch (NamingException e) {
e.printStackTrace();
}
}
System.out.println("onMessage() method returned...\n\n");
}
}
ejb-jar.xml
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/j2ee/ejb-jar_3_0.xsd"
version="3.0">
<enterprise-beans>
<message-driven>
<ejb-name>MyTimerMDB</ejb-name>
<ejb-class>my.examples.mdb.timer.MDBTimer
</ejb-class>
<resource-ref>
<description>My Default Timer Manager</description>
<res-ref-name>timer/MyDefaultTimer</res-ref-name>
<res-type>commonj.timer.TimerManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>
</message-driven>
</enterprise-beans>
Weblogic console output when message was posted.
Message received >> This is test message!!!
javax.naming.NameNotFoundException: While trying to look up comp/env/timer/MyDefaultTimer in /app/ejb/MyTimerMDB.jar#MyTimerMDB.; remaining name 'comp/env/timer/MyDefaultTimer'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException (BasicNamingNode.java:1139)
at weblogic.jndi.internal.ApplicationNamingNode.lookup(ApplicationNamingNode.java:144)
at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:380)
at weblogic.jndi.factories.java.ReadOnlyContextWrapper.lookup(ReadOnlyContextWrapper.java:45)
at weblogic.jndi.internal.AbstractURLContext.lookup(AbstractURLContext.java:130)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at my.examples.mdb.timer.MDBTimer.onMessage(MDBTimer.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:126)
at com.bea.core.repackaged.springframework.a开发者_JS百科op.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:114)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:126)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:114)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
at $Proxy89.onMessage(Unknown Source)
at weblogic.ejb.container.internal.MDListener.execute(MDListener.java:466)
at weblogic.ejb.container.internal.MDListener.transactionalOnMessage(MDListener.java:371)
at weblogic.ejb.container.internal.MDListener.onMessage(MDListener.java:327)
at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:4547)
at weblogic.jms.client.JMSSession.execute(JMSSession.java:4233)
at weblogic.jms.client.JMSSession.executeMessage(JMSSession.java:3709)
at weblogic.jms.client.JMSSession.access$000(JMSSession.java:114)
at weblogic.jms.client.JMSSession$UseForRunnable.run(JMSSession.java:5058)
at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:516)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
onMessage() method returned...
Can any one help out to resolve this problam
Thanks in advance :)
I did a silly mistake in ejb-jar.xml. I have given wrong resource type like commonj.timer.TimerManager. The actual name should be commonj.timers.TimerManager
Here I am giving updated ejb-jar.xml file.
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/j2ee/ejb-jar_3_0.xsd"
version="3.0">
<enterprise-beans>
<message-driven>
<ejb-name>MyTimerMDB</ejb-name>
<ejb-class>my.examples.mdb.timer.MDBTimer
</ejb-class>
<resource-ref>
<description>My Default Timer Manager</description>
<res-ref-name>timer/MyDefaultTimer</res-ref-name>
<res-type>commonj.timers.TimerManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>
</message-driven>
</enterprise-beans>
</ejb-jar>
Now I am able to look-up TimerMagers successfully
Thank you!!!!!
精彩评论