title: configuring Quartz CMT jobStore using Spring datasource
body: <p>I'm trying to confugre Quartz JobStoreCMT and use Spring's datasource as the managed datasource. Here is my Spring's config file with the datasource definition:</p>
  
  <pre><code>&lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close"&gt;
      &lt;property name="driverClassName" value="${database.driverClassName}" /&gt;
      &lt;property name="url" value="${database.url}" /&gt;
      &lt;property name="username" value="${database.username}" /&gt;
      &lt;property name="password" value="${database.password}" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Here is my quartz.properties:</p>
  
  <pre><code>org.quartz.jobStore.class: org.quartz.impl.jdbcjobstore.JobStoreCMT
  org.quartz.jobStore.driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
  org.quartz.jobStore.useProperties: false
  org.quartz.jobStore.dataSource = managedTXDS
  org.quartz.jobStore.nonManagedTXDataSource = qzDS
  org.quartz.jobStore.tablePrefix: QRTZ_
  org.quartz.jobStore.isClustered: false
  
  #============================================================================
  # Configure Datasources  
  #============================================================================
  org.quartz.dataSource.managedTXDS.jndiURL=java:comp/env/jdbc/dataSource
  
  org.quartz.dataSource.qzDS.driver: com.mysql.jdbc.Driver
  org.quartz.dataSource.qzDS.URL: jdbc:mysql://localhost:3306/myschema
  org.quartz.dataSource.qzDS.user: user
  org.quartz.dataSource.qzDS.password: pwd
  org.quartz.dataSource.qzDS.maxConnections: 5
  org.quartz.dataSource.qzDS.validationQuery=select 0 from dual
  </code></pre>
  
  <p>when I run my unit test that tries to initialize Scheduler I'm getting the following error:</p>
  
  <pre><code>2011-07-20 21:38:22,477 [main] ERROR org.quartz.utils.JNDIConnectionProvider - Error  looking up datasource: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
  javax.naming.NoInitialContextException: Need to specify class name in environment or  system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
  at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
  at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
  at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
  ...
  org.quartz.JobPersistenceException: Failed to obtain DB connection from data source 'managedTXDS': java.sql.SQLException: Could not retrieve datasource via JNDI url 'java:comp/env/jdbc/dataSource' javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial [See nested exception: java.sql.SQLException: Could not retrieve datasource via JNDI url 'java:comp/env/jdbc/dataSource' javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial]
  at org.quartz.impl.jdbcjobstore.JobStoreSupport.getConnection(JobStoreSupport.java:726)
  at org.quartz.impl.jdbcjobstore.JobStoreCMT.executeInLock(JobStoreCMT.java:231)
  </code></pre>
  
  <p>So, is this a problem with specifying the org.quartz.dataSource.managedTXDS.java.naming.factory.initial and/or org.quartz.dataSource.managedTXDS.jndiURL=java:comp/env/jdbc/dataSource ?</p>
  
  <p>If it is the JNDI factory setting that is missing - what should be the value for Spring?</p>
  
  <p>thanks!
  Marina</p>