这个是xml配置
<bean id="schedulerFactoryBean"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="dataSource" ref="myDataSource"></property>
<property name="configLocation" value="classpath:quartz.properties"/>
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:quartz.properties</value>
</list>
</property>
</bean>
<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${org.quartz.dataSource.myDS.driver}">
</property>
<property name="jdbcUrl" value="${org.quartz.dataSource.myDS.URL}">
</property>
<property name="user" value="${org.quartz.dataSource.myDS.user}"></property>
<property name="password" value="${org.quartz.dataSource.myDS.password}"></property>
</bean>
这个是quartz.properties
org.quartz.scheduler.instanceName = My_Quartz
org.quartz.scheduler.instanceId = AUTO
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 5
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.dataSource = myDS
org.quartz.dataSource.myDS.driver = com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL = jdbc:mysql://127.0.0.1:3306/quartz
org.quartz.dataSource.myDS.user = root
org.quartz.dataSource.myDS.password = root
org.quartz.dataSource.myDS.maxConnections = 10
不懂为什么在spring启动时初始化quartz无法获取jobstoreTX而是获取到org.springframework.scheduling.quartz.LocalDataSourceJobStore
有人知道为什么吗
------解决方案--------------------
设置了dataSource以后quartz会让spring来管理事物, LocalDataSourceJobStore里会调spring的
TransactionSynchronizationManager 开启并绑定数据库连接。
也就是org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX 完全没用, 具体你看代码就知道了