将 Spring 的 LocalTask​​ExecutorThreadPool 与 Quartz 结合使用

发布于 2024-10-20 01:01:15 字数 2301 浏览 5 评论 0原文

我尝试将 LocalTask​​ExecutorThreadPool 与石英一起使用,但是当我尝试将它用作石英任务执行器时,我收到此错误。

错误:

arg.springframework.beans.TypeMismatchException:无法转换类型的属性值 [org.springframework.scheduling.quartz.LocalTask​​ExecutorThreadPool] 为属性“taskExecutor”所需的类型 [org.springframework.core.task.TaskExecutor]。

Spring Config

<bean id="taskExecutor" class="org.springframework.scheduling.quartz.LocalTaskExecutorThreadPool">

</bean> 

<bean id="schedulerTarget" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" scope="singleton" lazy-init="false">
    <property name="applicationContextSchedulerContextKey">
        <value>applicationContext</value>
    </property>
    <property name="dataSource">
        <ref bean="dataSrcBean"/>
    </property>
    <property name="transactionManager">
        <ref bean="txManager" />
    </property>
    <property name="taskExecutor">
        <ref bean="taskExecutor" />
    </property>
    <property name="quartzProperties">
        <props>
            <prop key="org.quartz.jobStore.class">org.springframework.scheduling.quartz.LocalDataSourceJobStore</prop>
            <prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop> 
            <prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.MSSQLDelegate</prop>
            <prop key="org.quartz.jobStore.selectWithLockSQL">SELECT * FROM {0}LOCKS WHERE LOCK_NAME = ?</prop>
            <prop key="org.quartz.plugin.shutdownhook.class">org.quartz.plugins.management.ShutdownHookPlugin</prop>
            <prop key="org.quartz.plugin.shutdownhook.cleanShutdown">true</prop>
            <prop key="org.quartz.scheduler.instanceName">Sched1</prop>
            <prop key="org.quartz.scheduler.instanceId">1</prop>
            <prop key="org.quartz.scheduler.rmi.export">false</prop>
            <prop key="org.quartz.scheduler.rmi.proxy">false</prop>
        </props>
    </property>  
</bean>

这样做的全部目的是让Spring 控制quartz 建立的任何连接。我已经有一个由调度程序使用的 Spring 事务管理器,但调度程序似乎会在我的数据库上留下休眠连接。

特纳克斯

Im trying to use the LocalTaskExecutorThreadPool with quartz but when i try to use it as the quartz taskexecutor I get this error.

ERROR:

arg.springframework.beans.TypeMismatchException: Failed to convert property value of type
[org.springframework.scheduling.quartz.LocalTaskExecutorThreadPool] to required type [org.springframework.core.task.TaskExecutor] for property 'taskExecutor'.

Spring Config

<bean id="taskExecutor" class="org.springframework.scheduling.quartz.LocalTaskExecutorThreadPool">

</bean> 

<bean id="schedulerTarget" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" scope="singleton" lazy-init="false">
    <property name="applicationContextSchedulerContextKey">
        <value>applicationContext</value>
    </property>
    <property name="dataSource">
        <ref bean="dataSrcBean"/>
    </property>
    <property name="transactionManager">
        <ref bean="txManager" />
    </property>
    <property name="taskExecutor">
        <ref bean="taskExecutor" />
    </property>
    <property name="quartzProperties">
        <props>
            <prop key="org.quartz.jobStore.class">org.springframework.scheduling.quartz.LocalDataSourceJobStore</prop>
            <prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop> 
            <prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.MSSQLDelegate</prop>
            <prop key="org.quartz.jobStore.selectWithLockSQL">SELECT * FROM {0}LOCKS WHERE LOCK_NAME = ?</prop>
            <prop key="org.quartz.plugin.shutdownhook.class">org.quartz.plugins.management.ShutdownHookPlugin</prop>
            <prop key="org.quartz.plugin.shutdownhook.cleanShutdown">true</prop>
            <prop key="org.quartz.scheduler.instanceName">Sched1</prop>
            <prop key="org.quartz.scheduler.instanceId">1</prop>
            <prop key="org.quartz.scheduler.rmi.export">false</prop>
            <prop key="org.quartz.scheduler.rmi.proxy">false</prop>
        </props>
    </property>  
</bean>

The whole purpose of this is to have Spring control any connection quartz makes. I already have a Spring transaction manager being used by the scheduler but its seems the scheduler will leave sleeping connections on my db.

Thnaks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小猫一只 2024-10-27 01:01:15

您不应该自己使用 LocalTask​​ExecutorThreadPool - SchedulerFactoryBean 在内部使用它来将 TaskExecutor 包装在 Quartz 的 ThreadPool 接口中。

SchedulerFactoryBean 期望注入一个 taskExecutor 对象。您需要决定要使用 TaskExecutor 的哪种实现。

You shouldn't use LocalTaskExecutorThreadPool yourself - SchedulerFactoryBean uses this internally to wrap a TaskExecutor in Quartz's ThreadPool interface.

SchedulerFactoryBean expects a taskExecutor object to be injected. You need to decide which implementation of TaskExecutor that you want to use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文