2010-08-06 83 views
1

我在嘗試查找TimerManager時遇到了javax.naming.NameNotFoundException。 這裏我給MDB組件。如何在WebLogic 10.3環境中使用MDB中的commonJ Timer Manager

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控制檯outpu當消息被髮布時。

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.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.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... 

任何一個可以幫忙解決這個problam提前

謝謝:)

回答

0

我沒有在ejb-jar.xml一個愚蠢的錯誤。我給了錯誤的資源類型,如commonj.timer.TimerManager。實際名稱應該是commonj.timers.TimerManager

這裏我給出更新的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.timers.TimerManager</res-type> 
        <res-auth>Container</res-auth> 
        <res-sharing-scope>Unshareable</res-sharing-scope> 
       </resource-ref> 
      </message-driven> 
     </enterprise-beans> 
    </ejb-jar> 

現在我能夠查找TimerMagers成功

謝謝!!!!!

相關問題