我正在尝试使用Quartz JobStoreCMT,并使用Spring的数据源作为托管数据源。这是我的Spring配置文件,其中包含数据源定义:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${database.driverClassName}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
</bean>
这是我的quartz.properties:
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
当我运行尝试初始化Scheduler的单元测试时,我收到以下错误:
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)
那么,这是指定org.quartz.dataSource.managedTXDS.java.naming.factory.initial和/或org.quartz.dataSource.managedTXDS.jndiURL = java:comp / env / jdbc / dataSource的问题吗?
如果缺少JNDI工厂设置 - Spring应该是什么值?
谢谢! 码头
答案 0 :(得分:1)
请看看@
将其设为
org.quartz.jobStore.class = org.springframework.scheduling.quartz.LocalDataSourceJobStore