Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Websphere JNDI查找在Quartz作业中失败_Java_Quartz Scheduler_Ejb 3.1_Websphere Liberty - Fatal编程技术网

Java Websphere JNDI查找在Quartz作业中失败

Java Websphere JNDI查找在Quartz作业中失败,java,quartz-scheduler,ejb-3.1,websphere-liberty,Java,Quartz Scheduler,Ejb 3.1,Websphere Liberty,做一些可以帮助我在Quartz作业中进行EJB初始化的事情 我有这样的石英: @DisallowConcurrentExecution public class TestJob implements Job{ private TestEJBServiceLocal testEJBService; private void initEJB() { this.testEJBService = new JNDIUtil() .getByJndiName("java:c

做一些可以帮助我在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>
我正在运行IBM Liberty profile V.8.5.5.5

更新

我试图更新JNDI查找字符串(全局JNDI在应用程序启动期间在
trace.log
中打印),但仍然得到相同的异常。以下是我在作业中的更新:

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的完整JNDI名称Hi@Gas你能提供一个完整JNDI名称的示例吗?@Mindaugas在答案中添加了示例。我已经用你的示例更新了代码。我仍然收到相同的错误。@Mindaugas由于不再有java:comp/env调用,您不能有完全相同的错误,因此请更新您的错误消息或确保您使用更改重新部署应用程序。我已添加控制台输出日志。
    [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
    
    [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
    
    ctx.lookup("java:global/HelloEJBLocal/Hello!test.Hello");