赞
踩
最近接手了一个比较老的一个项目,是通过外部引入Tomcat来进行启动,然后项目中的定时任务也是使用的Spring的Quartz,然后要加一个定时任务,毕竟是接手的项目,一边CV,一边看着Spring的文档。不能白白的抄,要抄的明白嘛。然后在运行的时候突然就发现加的定时任务就没有生效。
代码如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- 每天2点处理百世仓出库单并在早上8点发送商品出库短信提醒 --> <bean id="terminalSurverllant5" class="cn.vcu.job.StockTaskServiceJob"></bean> <!-- 凌晨2点同步百世仓出库数据 --> <bean id="jobtask21" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> <ref bean="terminalSurverllant5" /> </property> <property name="targetMethod"> <value>shortMessage</value> </property> </bean> <!-- 2点处理百世仓出库数据 --> <bean id="doTime21" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="jobtask21" /> </property> <property name="cronExpression"> <value>0 0 12 * * ?</value> </property> </bean> <bean id="quartzInterceptor" class="cn.vcu.web.interceptor.QuartzInterceptor"/> <bean id="quartzProxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"> <list> <value>terminalSurverllant</value> </list> </property> <property name="interceptorNames"> <list> <value>quartzInterceptor</value> </list> </property> </bean> <!-- profile="test,online" --> <beans profile="test,online"> <bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="doTime21" /> </list> </property> </bean> </beans> <beans profile="dev"> <bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="doTime21" /> </list> </property> </bean> </beans> </beans>
对于定时任务的代码我就不做过多的赘述:可以点击参考Spring官网
因为自己也确信自己的代码没有问题,于是就在排查,就别人已经好用的定时任务注释点,然后发现代码注释了,竟然也能执行。 就知道是war包没有更新的原因。其实本可以通过maven重新编译就行。但是每次编译也很费劲。于是就从tomcat里下文章。
直到我看到了这里,如图圈中的地方。
只有打钩,就会在项目对应的目录生成war包。反之,如果不打勾“Include in project build”,那么生成项目(Ctrl+F9)的时候就不会生成war包

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。