[英]How to configure quartz scheduler with spring-style properties file in Tomcat?
我在Apache Tomcat上有一个Web应用程序。 该Web应用程序使用Quartz Scheduler 。 我使用-D
开关从类路径中加载了quartz.properties
,该开关包含以下属性:
quartz.jndi=java:comp/env/something
org.quartz.dataSource.myJndiName.jndiURL=${quartz.jndi}
但这不起作用。 也许${quartz.jndi}
仅在Spring Context中通过PropertyPlaceholderConfigurer
bean工作? 是否可以在Spring中为Quartz Scheduler加载此属性文件?
一年多以后,我知道了,但希望对某人有用:您可以通过在Spring上下文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文件中还有一些其他配置。
您可以在SchedulerFactoryBean中设置configLocation
:
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="configLocation" value="classpath:quartz.properties" />
[...]
</bean>
这取决于您想要哪种Quartz属性,可能已经有了传递它的春季之路。 通常要在 Spring 3之前和之后引用属性条目(非Quartz特定), 请看这个问题 。 对于特定于Quartz的Spring设置和配置,请参阅Spring调度文档的第一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.