使用IBM Web Sphere 8.5在struts2中实现石英调度程序,未找到JNDI名称

问题描述

我正在尝试使用IBM Websphere 8.5在struts 2中实现石英。当我尝试建立数据库连接时,我得到的是javax.naming.NameNotFoundException。下面列出了简短的代码错误日志的详细信息。

public class InvengerScheduledJob_3250 implements Job {
    
    @Override
    public void execute(JobExecutionContext arg0) throws JobExecutionException {
        try {
            ApplicationContext.getInstance().getConnection();
        } catch (Exception e) {
            e.printstacktrace();
        }
    }

// Singleton class
public class ApplicationContext {

public Connection getConnection() throws Exception{

      Connection conn=null;
      if ( dbProperties == null ) { 
         throw new Exception("Connection Properties not set.."); 
      }
      
      try {
         
         Context ctx = new InitialContext(); 
         DataSource ds = getDataSource();

         // Changed to get connection without username and password
         conn=ds.getConnection();
         conn.setAutoCommit(true);  
         
         
      }
      catch(Exception e) {
         isErrorOnLoad = true;
         PersistenceUtil.releaseConn(conn);
      }
      return conn;
   }
   
   public DataSource getDataSource() throws Exception {
       Context ctx = null;
       DataSource ds = null;
       try {
           ctx = new InitialContext(); 
           ds = (DataSource)ctx.lookup("java:comp/env/jdbc/ds1");
        } catch (Exception e) {
            e.printstacktrace();
        }
         
        return ds;
    }
   
 }
// property file. when I create quartz.properties file under resources folder scheduler stops working
// so i kept quartz properties in ApplicationResource properties files
ApplicationResource.properties 

org.quartz.threadExecutor.class=org.quartz.commonj.WorkManagerThreadExecutor
org.quartz.threadExecutor.workManagerName=wm/default

错误

[21/10/20 22:01:20:006 PDT] 00000115 SystemOut     O ***************** InvengerScheduledJob_3250 execute ****************
[21/10/20 22:01:20:010 PDT] 000000cc SystemOut     O ***************** InvengerScheduledJob_3250 execute ****************
[21/10/20 22:01:20:015 PDT] 000000ee SystemOut     O ***************** InvengerScheduledJob_3250 execute ****************
[21/10/20 22:01:20:003 PDT] 00000115 SystemErr     R javax.naming.ConfigurationException: A JNDI operation on a "java:" name cannot be completed because the server runtime is not able to associate the operation's thread with any J2EE application component.  This condition can occur when the JNDI client using the "java:" name is not executed on the thread of a server application request.  Make sure that a J2EE application does not execute JNDI operations on "java:" names within static code blocks or in threads created by that J2EE 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:" names. [Root exception is javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".]
[21/10/20 22:01:20:004 PDT] 00000115 SystemErr     R    at com.ibm.ws.naming.java.javaURLContextImpl.throwExceptionIfDefaultJavaNS(javaURLContextImpl.java:522)
[21/10/20 22:01:20:004 PDT] 00000115 SystemErr     R    at com.ibm.ws.naming.java.javaURLContextImpl.throwConfigurationExceptionWithDefaultJavaNS(javaURLContextImpl.java:552)
[21/10/20 22:01:20:004 PDT] 00000115 SystemErr     R    at com.ibm.ws.naming.java.javaURLContextImpl.lookupExt(javaURLContextImpl.java:481)
[21/10/20 22:01:20:004 PDT] 00000115 SystemErr     R    at com.ibm.ws.naming.java.javaURLContextRoot.lookupExt(javaURLContextRoot.java:485)
[21/10/20 22:01:20:004 PDT] 00000115 SystemErr     R    at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:370)
[21/10/20 22:01:20:004 PDT] 00000115 SystemErr     R    at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161)
[21/10/20 22:01:20:004 PDT] 00000115 SystemErr     R    at javax.naming.InitialContext.lookup(InitialContext.java:423)
[21/10/20 22:01:20:004 PDT] 00000115 SystemErr     R    at com.safecofis.agilstream.webapplication.ApplicationContext.getDataSource(ApplicationContext.java:762)
[21/10/20 22:01:20:005 PDT] 00000115 SystemErr     R    at com.safecofis.agilstream.webapplication.ApplicationContext.getConnection(ApplicationContext.java:704)
[21/10/20 22:01:20:005 PDT] 00000115 SystemErr     R    at com.assurant.invenger.scheduler.InvengerScheduledJob_3250.execute(InvengerScheduledJob_3250.java:28)
[21/10/20 22:01:20:005 PDT] 00000115 SystemErr     R    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
[21/10/20 22:01:20:005 PDT] 00000115 SystemErr     R    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
[21/10/20 22:01:20:005 PDT] 00000115 SystemErr     R Caused by: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".
[21/10/20 22:01:20:005 PDT] 00000115 SystemErr     R    at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1969)
[21/10/20 22:01:20:005 PDT] 00000115 SystemErr     R    at com.ibm.ws.naming.ipbase.NameSpace.retrieveBinding(NameSpace.java:1376)
[21/10/20 22:01:20:005 PDT] 00000115 SystemErr     R    at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1219)
[21/10/20 22:01:20:006 PDT] 00000115 SystemErr     R    at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:1141)
[21/10/20 22:01:20:006 PDT] 00000115 SystemErr     R    at com.ibm.ws.naming.urlbase.UrlContextImpl.lookupExt(UrlContextImpl.java:1436)
[21/10/20 22:01:20:006 PDT] 00000115 SystemErr     R    at com.ibm.ws.naming.java.javaURLContextImpl.lookupExt(javaURLContextImpl.java:477)
[21/10/20 22:01:20:006 PDT] 00000115 SystemErr     R    ... 9 more
[21/10/20 22:01:20:007 PDT] 000000cc SystemErr     R javax.naming.ConfigurationException: A JNDI operation on a "java:" name cannot be completed because the server runtime is not able to associate the operation's thread with any J2EE application component.  This condition can occur when the JNDI client using the "java:" name is not executed on the thread of a server application request.  Make sure that a J2EE application does not execute JNDI operations on "java:" names within static code blocks or in threads created by that J2EE 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:" names. [Root exception is javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".]
[21/10/20 22:01:20:007 PDT] 000000cc SystemErr     R    at com.ibm.ws.naming.java.javaURLContextImpl.throwExceptionIfDefaultJavaNS(javaURLContextImpl.java:522)
[21/10/20 22:01:20:007 PDT] 000000cc SystemErr     R    at com.ibm.ws.naming.java.javaURLContextImpl.throwConfigurationExceptionWithDefaultJavaNS(javaURLContextImpl.java:552)
[21/10/20 22:01:20:007 PDT] 000000cc SystemErr     R    at com.ibm.ws.naming.java.javaURLContextImpl.lookupExt(javaURLContextImpl.java:481)
[21/10/20 22:01:20:007 PDT] 000000cc SystemErr     R    at com.ibm.ws.naming.java.javaURLContextRoot.lookupExt(javaURLContextRoot.java:485)
[21/10/20 22:01:20:008 PDT] 000000cc SystemErr     R    at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:370)
[21/10/20 22:01:20:008 PDT] 000000cc SystemErr     R    at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161)
[21/10/20 22:01:20:008 PDT] 000000cc SystemErr     R    at javax.naming.InitialContext.lookup(InitialContext.java:423)
[21/10/20 22:01:20:008 PDT] 000000cc SystemErr     R    at com.safecofis.agilstream.webapplication.ApplicationContext.getDataSource(ApplicationContext.java:762)
[21/10/20 22:01:20:008 PDT] 000000cc SystemErr     R    at com.safecofis.agilstream.webapplication.ApplicationContext.getConnection(ApplicationContext.java:704)
[21/10/20 22:01:20:008 PDT] 000000cc SystemErr     R    at com.assurant.invenger.scheduler.InvengerScheduledJob_3250.execute(InvengerScheduledJob_3250.java:28)
[21/10/20 22:01:20:008 PDT] 000000cc SystemErr     R    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
[21/10/20 22:01:20:008 PDT] 000000cc SystemErr     R    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
[21/10/20 22:01:20:008 PDT] 000000cc SystemErr     R Caused by: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".
[21/10/20 22:01:20:009 PDT] 000000cc SystemErr     R    at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1969)
[21/10/20 22:01:20:009 PDT] 000000cc SystemErr     R    at com.ibm.ws.naming.ipbase.NameSpace.retrieveBinding(NameSpace.java:1376)
[21/10/20 22:01:20:009 PDT] 000000cc SystemErr     R    at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1219)
[21/10/20 22:01:20:009 PDT] 000000cc SystemErr     R    at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:1141)
[21/10/20 22:01:20:009 PDT] 000000cc SystemErr     R    at com.ibm.ws.naming.urlbase.UrlContextImpl.lookupExt(UrlContextImpl.java:1436)
[21/10/20 22:01:20:009 PDT] 000000cc SystemErr     R    at com.ibm.ws.naming.java.javaURLContextImpl.lookupExt(javaURLContextImpl.java:477)
[21/10/20 22:01:20:009 PDT] 000000cc SystemErr     R    ... 9 more
[21/10/20 22:01:20:012 PDT] 000000ee SystemErr     R javax.naming.ConfigurationException: A JNDI operation on a "java:" name cannot be completed because the server runtime is not able to associate the operation's thread with any J2EE application component.  This condition can occur when the JNDI client using the "java:" name is not executed on the thread of a server application request.  Make sure that a J2EE application does not execute JNDI operations on "java:" names within static code blocks or in threads created by that J2EE 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:" names. [Root exception is javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".]
[21/10/20 22:01:20:013 PDT] 000000ee SystemErr     R    at com.ibm.ws.naming.java.javaURLContextImpl.throwExceptionIfDefaultJavaNS(javaURLContextImpl.java:522)
[21/10/20 22:01:20:013 PDT] 000000ee SystemErr     R    at com.ibm.ws.naming.java.javaURLContextImpl.throwConfigurationExceptionWithDefaultJavaNS(javaURLContextImpl.java:552)
[21/10/20 22:01:20:013 PDT] 000000ee SystemErr     R    at com.ibm.ws.naming.java.javaURLContextImpl.lookupExt(javaURLContextImpl.java:481)
[21/10/20 22:01:20:013 PDT] 000000ee SystemErr     R    at com.ibm.ws.naming.java.javaURLContextRoot.lookupExt(javaURLContextRoot.java:485)
[21/10/20 22:01:20:013 PDT] 000000ee SystemErr     R    at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:370)
[21/10/20 22:01:20:013 PDT] 000000ee SystemErr     R    at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161)
[21/10/20 22:01:20:013 PDT] 000000ee SystemErr     R    at javax.naming.InitialContext.lookup(InitialContext.java:423)
[21/10/20 22:01:20:013 PDT] 000000ee SystemErr     R    at com.safecofis.agilstream.webapplication.ApplicationContext.getDataSource(ApplicationContext.java:762)
[21/10/20 22:01:20:014 PDT] 000000ee SystemErr     R    at com.safecofis.agilstream.webapplication.ApplicationContext.getConnection(ApplicationContext.java:704)
[21/10/20 22:01:20:014 PDT] 000000ee SystemErr     R    at com.assurant.invenger.scheduler.InvengerScheduledJob_3250.execute(InvengerScheduledJob_3250.java:28)
[21/10/20 22:01:20:014 PDT] 000000ee SystemErr     R    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
[21/10/20 22:01:20:014 PDT] 000000ee SystemErr     R    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
[21/10/20 22:01:20:014 PDT] 000000ee SystemErr     R Caused by: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".
[21/10/20 22:01:20:014 PDT] 000000ee SystemErr     R    at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1969)
[21/10/20 22:01:20:014 PDT] 000000ee SystemErr     R    at com.ibm.ws.naming.ipbase.NameSpace.retrieveBinding(NameSpace.java:1376)
[21/10/20 22:01:20:014 PDT] 000000ee SystemErr     R    at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1219)
[21/10/20 22:01:20:014 PDT] 000000ee SystemErr     R    at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:1141)
[21/10/20 22:01:20:015 PDT] 000000ee SystemErr     R    at com.ibm.ws.naming.urlbase.UrlContextImpl.lookupExt(UrlContextImpl.java:1436)
[21/10/20 22:01:20:015 PDT] 000000ee SystemErr     R    at com.ibm.ws.naming.java.javaURLContextImpl.lookupExt(javaURLContextImpl.java:477)
[21/10/20 22:01:20:015 PDT] 000000ee SystemErr     R    ... 9 more

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)