Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用quartz触发器调度类/bean?_Java_Spring_Quartz Scheduler - Fatal编程技术网

Java 使用quartz触发器调度类/bean?

Java 使用quartz触发器调度类/bean?,java,spring,quartz-scheduler,Java,Spring,Quartz Scheduler,我正在使用Spring3。我有一个豆子需要安排。我的应用程序生成的是Jar而不是war。我需要在tomcat中部署jar来触发作业吗 谢谢 绝对不是。如果您使用Quartz计划和执行作业,那么您也可以在独立Java应用程序中使用它。在Spring配置中,您应该有如下内容(假设您正在使用JDBC作业存储来持久化作业和触发器): ${scheduler.org.quartz.scheduler.instanceId} ${scheduler.org.quartz.scheduler.Instanc

我正在使用
Spring3
。我有一个豆子需要安排。我的应用程序生成的是
Jar
而不是
war
。我需要在tomcat中部署jar来触发作业吗


谢谢

绝对不是。如果您使用Quartz计划和执行作业,那么您也可以在独立Java应用程序中使用它。在Spring配置中,您应该有如下内容(假设您正在使用JDBC作业存储来持久化作业和触发器):


${scheduler.org.quartz.scheduler.instanceId}
${scheduler.org.quartz.scheduler.InstanceIdgeGenerator.class}
${scheduler.org.quartz.jobStore.driverDelegateClass}
${scheduler.org.quartz.jobStore.tablePrefix}
${scheduler.org.quartz.jobStore.isClustered}
${scheduler.org.quartz.jobStore.selectWithLockSQL}
${scheduler.org.quartz.jobStore.lockHandler.class}
真的
60000
真的
真的
真的
...
...
这将使用指定的作业和触发器列表创建Quartz调度程序bean。计划程序将在应用程序启动时自动启动

您会注意到,上面的应用程序上下文片段对某些值使用了属性占位符。您需要使用有效值展开这些占位符。有关详细信息,请参阅Quartz文档。在大多数情况下,您可以使用默认值

<!--
  QuartzDesk scheduler.
-->
<bean id="scheduler"
    class="org.springframework.scheduling.quartz.SchedulerFactoryBean">

  <property name="schedulerName" value="YourSchedulerName"/>

  <property name="autoStartup" value="true"/>

  <property name="waitForJobsToCompleteOnShutdown" value="true"/>

  <property name="dataSource" ref="dataSource"/>

  <property name="overwriteExistingJobs" value="true"/>

  <property name="quartzProperties">
    <props>
      <prop key="org.quartz.scheduler.instanceId">${scheduler.org.quartz.scheduler.instanceId}</prop>
      <prop key="org.quartz.scheduler.instanceIdGenerator.class">${scheduler.org.quartz.scheduler.instanceIdGenerator.class}</prop>
      <prop key="org.quartz.jobStore.driverDelegateClass">${scheduler.org.quartz.jobStore.driverDelegateClass}</prop>

      <prop key="org.quartz.jobStore.tablePrefix">${scheduler.org.quartz.jobStore.tablePrefix}</prop>
      <prop key="org.quartz.jobStore.isClustered">${scheduler.org.quartz.jobStore.isClustered}</prop>
      <prop key="org.quartz.jobStore.selectWithLockSQL">${scheduler.org.quartz.jobStore.selectWithLockSQL}</prop>
      <prop key="org.quartz.jobStore.lockHandler.class">${scheduler.org.quartz.jobStore.lockHandler.class}</prop>

      <!--
        The "use properties" flag instructs JDBCJobStore that all values in JobDataMaps will be Strings, and therefore can be stored as name-value pairs, rather than storing more complex objects in their serialized form in the BLOB column. This is can be handy, as you avoid the class versioning issues that can arise from serializing your non-String classes into a BLOB.
      -->
      <prop key="org.quartz.jobStore.useProperties">true</prop>

      <!--
        The the number of milliseconds the scheduler will 'tolerate' a trigger to pass its next-fire-time by, before being considered "misfired". The default value (if you don't make an entry of this property in your configuration) is 60000 (60 seconds).
      -->
      <prop key="org.quartz.jobStore.misfireThreshold">60000</prop>

      <!--
        Configures Quartz to expose the scheduler through an MBean in the JMX MBeanServer.
      -->
      <prop key="org.quartz.scheduler.jmx.export">true</prop>

      <!--
        The scheduler thread will be marked as a daemon thread.
      -->
      <prop key="org.quartz.scheduler.makeSchedulerThreadDaemon">true</prop>
      <!--
        The scheduler thread pool threads will be marked as daemon threads.
      -->
      <prop key="org.quartz.threadPool.makeThreadsDaemons">true</prop>
    </props>
  </property>

  <property name="jobFactory">
    <bean class="org.springframework.scheduling.quartz.SpringBeanJobFactory"/>
  </property>

  <property name="jobDetails" ref="jobDetails"/>

  <property name="triggers" ref="jobTriggers"/>

  <!--
    Name of the property in the scheduler context the Spring application context
    will be exposed through.
  -->
  <property name="applicationContextSchedulerContextKey" value="applicationContext"/>
</bean>

<!--
  jobDetails list contains all jobs that will be added to the QuartzDesk scheduler.
-->
<bean id="jobDetails" class="java.util.ArrayList">
  <constructor-arg>
    <list>
      <ref bean="yourJob1"/>
    </list>
  </constructor-arg>
</bean>

<!--
  jobTriggers list contains all triggers that will be added to the QuartzDesk scheduler.
-->
<bean id="jobTriggers" class="java.util.ArrayList">
  <constructor-arg>
    <list>
      <ref bean="yourTrigger1"/>
      ...
    </list>
  </constructor-arg>
</bean>


<bean id="yourJob1" class="org.quartz.impl.JobDetailImpl">
  <property name="jobClass" value="your job fqcn"/>
  <property name="group" value="someJobGroup"/>
  <property name="name" value="YourJob1"/>

  <property name="description"
            value="Job that does this and that..."/>

  <property name="durability" value="true"/>

  <property name="jobDataMap">
    <bean class="org.quartz.JobDataMap">
        <constructor-arg>
          <map>
            <entry key="param1" value="value1"/>
            ...
          </map>
        </constructor-arg>
    </bean>
  </property>
</bean>


<bean id="yourTrigger1"
      class="org.quartz.impl.triggers.CronTriggerImpl">
  <property name="name" value="YourTrigger1"/>
  <property name="group" value="someTriggerGroup"/>
  <property name="jobName" value="YourJob1"/>
  <property name="jobGroup" value="someJobGroup"/>
  <property name="description" value="CRON trigger."/>
  <!-- ss mm hh day-of-month month day-of-week year -->
  <property name="cronExpression" value="some cron trigger expression"/>
</bean>