注意:比较低版本的spring不支持0 59 23 L * ?的写法,会报无法解析L符号的错误,建议改为高版本spring

<!-- spring定时器 -->
      <bean id="methodInvokingJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">  
       <property name="targetObject">
       <ref bean="taskCount"/>
       </property>  
       <property name="targetMethod">
       <value>autoCountTimes</value>
       </property>  
   </bean>
   <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">  
       <property name="jobDetail">  
           <ref bean="methodInvokingJobDetail"/>  
       </property>  
       <!-- 配置每个月的最后一天的23点59分,调用修改用户月登陆次数的方法 -->
       <property name="cronExpression">  
           <value>0 59 23 L * ?</value>  
       </property>  
   </bean>
   <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">  
       <property name="triggers">  
           <list><ref local="cronTrigger"/></list>  
       </property>  
    </bean> 

我采用了和quartz方式的.其中里面的taskCount是我在bean里面配置的要执行定时任务的那个bean的id,
autoCountTimes指的是要执行的那个方法.这样就可以用带L那个corn表达式了.

Logo

脑启社区是一个专注类脑智能领域的开发者社区。欢迎加入社区,共建类脑智能生态。社区为开发者提供了丰富的开源类脑工具软件、类脑算法模型及数据集、类脑知识库、类脑技术培训课程以及类脑应用案例等资源。

更多推荐