问题描述
我在 Apache Tomcat 上有一个 Web 应用程序.Web 应用程序使用 Quartz Scheduler.我使用包含以下属性的 -D
开关从类路径加载 quartz.properties
:
I have a web application on Apache Tomcat. The web application uses the Quartz Scheduler. I load the quartz.properties
from the classpath with the -D
switch which contains the following properties:
quartz.jndi=java:comp/env/something
org.quartz.dataSource.myJndiName.jndiURL=${quartz.jndi}
但它不起作用.也许,${quartz.jndi}
只能在 Spring Context 中使用 PropertyPlaceholderConfigurer
bean?是否可以在 Spring 中为 Quartz Scheduler 加载此属性文件?
But it isn't working. Maybe, the ${quartz.jndi}
only works in Spring Context with the PropertyPlaceholderConfigurer
bean? Is it possible to load this properties file in Spring for the Quartz Scheduler?
推荐答案
一年多后我知道了,但希望对某人有用:您可以通过在 Spring 上下文 xml 中设置属性来实现此目的:
Over a year later I know, but hopefully useful to somebody: you can accomplish this by setting the properties inside your Spring context xml:
<bean name="schedulerFactory" depends-on="flyway" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="quartzProperties">
<map>
<entry key="org.quartz.threadPool.class" value="org.quartz.simpl.SimpleThreadPool" />
<entry key="org.quartz.jobStore.useProperties" value="true" />
<entry key="org.quartz.jobStore.class" value="org.quartz.impl.jdbcjobstore.JobStoreTX" />
<entry key="org.quartz.jobStore.driverDelegateClass" value="org.quartz.impl.jdbcjobstore.StdJDBCDelegate" />
<entry key="org.quartz.jobStore.tablePrefix" value="QRTZ_" />
<entry key="org.quartz.jobStore.dataSource" value="qzDS" />
<entry key="org.quartz.dataSource.qzDS.jndiURL" value="java:comp/env/jdbc/${jndi.dataSource}"/>
</map>
</property>
<property name="applicationContextSchedulerContextKey">
<value>applicationContext</value>
</property>
</bean>
请注意,我已将大部分与 JobStore 相关的属性放在此处,因为它们似乎需要位于同一位置.通常的quartz.properties 文件中还有一些其他配置.
Notice I've put most of the JobStore-related properties in here as they seem to need to be in the same place. There is still some other configuration in the usual quartz.properties file.
这篇关于如何在Tomcat中使用spring风格的属性文件配置quartz调度程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!