簡體   English   中英

Websphere JNDI查找在Quartz作業中失敗

[英]Websphere JNDI lookup fails in a Quartz job

做一些可以幫助我完成Quartz作業中的EJB的工作

我有這樣的石英:

@DisallowConcurrentExecution
public class TestJob implements Job{

private TestEJBServiceLocal testEJBService;

private void initEJB() {
   this.testEJBService = new JNDIUtil()
            .getByJndiName("java:comp/env/ejb/TestEJBService");
}
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
    // DO STUFF
}
}

在Web XML中,我有:

<ejb-local-ref>
        <description />
        <ejb-ref-name>ejb/TestEJBService</ejb-ref-name>
        <ejb-ref-type>Session</ejb-ref-type>
        <local-home />
        <local>com.ibm.blue.ejb.TestEJBServiceLocal</local>
        <ejb-link>TestEJBService</ejb-link>
    </ejb-local-ref>

Liberty概要文件無法初始化EJB並帶有異常:

2015-06-04 16:18:00 ERROR JNDIUtil:38 - JNDIUtil lookup error;
javax.naming.NamingException: CWNEN1000E: A JNDI operation on a java:comp/env name cannot be completed because the current thread is not associated with a Java Enterprise Edition application component. This condition can occur when the JNDI client using the java:comp/env name does not occur on the thread of a server application request. Make sure that a Java EE application does not run JNDI operations on java:comp/env names within static code blocks or in threads created by that application. Such code does not necessarily run on the thread of a server application request and therefore is not supported by JNDI operations on java:comp/env names.
    at com.ibm.ws.injectionengine.osgi.internal.naming.InjectionJavaColonHelper.getInjectionScopeData(InjectionJavaColonHelper.java:110)
    at com.ibm.ws.injectionengine.osgi.internal.naming.InjectionJavaColonHelper.getObjectInstance(InjectionJavaColonHelper.java:67)
    at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLContext.lookup(JavaURLContext.java:319)
    at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLContext.lookup(JavaURLContext.java:357)
    at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161)
    at javax.naming.InitialContext.lookup(InitialContext.java:423)
    at JNDIUtil.lookup(JNDIUtil.java:36)
    at getByJndiName(JNDIUtil.java:24)
    at Job.initEJB(Job.java:52)
    at execute(Job.java:68)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
2015-06-04 16:18:00 ERROR JNDIUtil:38 - JNDIUtil lookup error;

我正在運行IBM Liberty概要文件V.8.5.5.5

更新

我嘗試更新JNDI查找字符串(在應用程序啟動期間在trace.log打印了全局JNDI)我仍然遇到相同的異常。 這是我在工作中的更新:

private void initEJB() {
   Context context;
   String jndi = "java:global/TestEAR/TestEJBS/TestEJBService!com.ibm.blue.ejb.TestEJBServiceLocal"
   try{
      context = new InitialContext();
      this.testEJBService = (TestEJBServiceLocal)context.lookup(jndi); 
       } catch (NamingException e) {
        System.out.println("-->Test with InitialContext: Error");
        e.printStackTrace();
    }
  try {
        this.testEJBService = new JNDIUtil().getByJndiName(jndi);
    } catch (Exception e) {
        System.err.println("-->Test with JNDIUtil: Error");
        e.printStackTrace();
    }
 }

這是輸出日志:

[err] -->Test with InitialContext: Error
[err] javax.naming.NamingException: CWNEN1000E: A JNDI operation on a java:comp/env name cannot be completed because the current thread is not associated with a Java Enterprise Edition application component. This condition can occur when the JNDI client using the java:comp/env name does not occur on the thread of a server application request. Make sure that a Java EE application does not run JNDI operations on java:comp/env names within static code blocks or in threads created by that application. Such code does not necessarily run on the thread of a server application request and therefore is not supported by JNDI operations on java:comp/env names.
[err]   at com.ibm.ws.injectionengine.osgi.internal.naming.InjectionJavaColonHelper.getInjectionScopeData(InjectionJavaColonHelper.java:110)
[err]   at com.ibm.ws.injectionengine.osgi.internal.naming.InjectionJavaColonHelper.getObjectInstance(InjectionJavaColonHelper.java:67)
[err]   at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLContext.lookup(JavaURLContext.java:319)
[err]   at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLContext.lookup(JavaURLContext.java:357)
[err]   at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161)
[err]   at javax.naming.InitialContext.lookup(InitialContext.java:423)
[err]   at Job.initEJB(Job.java:38)
[err]   at execute(Job.java:75)
[err]   at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
[err]   at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
[err] -->Test with JNDIUtil: Error
[err] java.lang.RuntimeException: Cannot get bean by JNDI name; JNDI=java:global/TestEAR/TestEJBS/TestEJBService!com.ibm.blue.ejb.TestEJBServiceLocal
[err]   at JNDIUtil.lookup(JNDIUtil.java:39)
[err]   at JNDIUtil.getByJndiName(JNDIUtil.java:24)
[err]   at initEJB(Job.java:62)
[err]   at Job.execute(Job.java:75)
[err]   at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
[err]   at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
[err] Caused by: 
[err] javax.naming.NamingException: CWNEN1000E: A JNDI operation on a java:comp/env name cannot be completed because the current thread is not associated with a Java Enterprise Edition application component. This condition can occur when the JNDI client using the java:comp/env name does not occur on the thread of a server application request. Make sure that a Java EE application does not run JNDI operations on java:comp/env names within static code blocks or in threads created by that application. Such code does not necessarily run on the thread of a server application request and therefore is not supported by JNDI operations on java:comp/env names.
[err]   at com.ibm.ws.injectionengine.osgi.internal.naming.InjectionJavaColonHelper.getInjectionScopeData(InjectionJavaColonHelper.java:110)
[err]   at com.ibm.ws.injectionengine.osgi.internal.naming.InjectionJavaColonHelper.getObjectInstance(InjectionJavaColonHelper.java:67)
[err]   at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLContext.lookup(JavaURLContext.java:319)
[err]   at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLContext.lookup(JavaURLContext.java:357)
[err]   at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161)
[err]   at javax.naming.InitialContext.lookup(InitialContext.java:423)
[err]   at JNDIUtil.lookup(JNDIUtil.java:36)
[err]   ... 5 more

Quartz使用非托管線程,因此java:comp / env命名空間和引用在那里不可用。

您可以:

  • 請使用EJB <=== UPDATE2的完整JNDI名稱。 目前,我無法使其通過非托管線程與本地接口一起運行(我現在沒有時間再使用它)。 因此,您要么需要使用支持遠程EJB的Liberty Beta,要么將您的bean更改為具有遠程接口。 或者,您可以嘗試將Quartz配置為使用Liberty並發功能提供的托管線程工廠(類似此處的方式 (但這是用於完整的WAS)。我沒有嘗試過,所以不知道它是否確實可行) 。

  • 或者,可能會更好,而不是使用Quartz

    • WebSphere Liberty的concurrent-1.0功能,該功能使用托管線程並有權訪問Java EE上下文,例如托管的計划執行程序
    • 或使用EJB Timers和@Schedule批注。

更新
當它被服務器綁定時,您可以在消息日志中找到完整的JNDI名稱,如下所示:

[INFO    ] CNTR0167I: The server is binding the test.Hello interface of the Hello enterprise bean in the HelloEJBLocal.war module of the HelloEJBLocal application.  
The binding location is: java:global/HelloEJBLocal/Hello!test.Hello

然后您使用查找(僅適用於Java EE應用程序組件或托管線程):

ctx.lookup("java:global/HelloEJBLocal/Hello!test.Hello");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM