I'm trying to implement quartz with struts 2 using IBM websphere 8.5. When I'm trying to get database connection I'm getting javax.naming.NameNotFoundException
. Below listed the code in short and error log details.
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
Error :
[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