如何在Tomcat中使用spring-style属性文件配置quartz scheduler?

use*_*862 3 java spring tomcat quartz-scheduler

我在Apache Tomcat上有一个Web应用程序.Web应用程序使用Quartz Scheduler.我quartz.properties使用-D包含以下属性的开关从类路径加载:

quartz.jndi=java:comp/env/something
org.quartz.dataSource.myJndiName.jndiURL=${quartz.jndi}
Run Code Online (Sandbox Code Playgroud)

但它没有用.也许,${quartz.jndi}唯一可以在Spring Context中使用PropertyPlaceholderConfigurerbean吗?是否可以在Spring中为Quartz Scheduler加载此属性文件?

Tom*_*omL 9

一年后我知道,但希望对某人有用:你可以通过在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>
Run Code Online (Sandbox Code Playgroud)

请注意,我已将大多数与JobStore相关的属性放在此处,因为它们似乎需要位于同一位置.通常的quartz.properties文件中还有一些其他配置.