一个简单的Quartz定时任务
package com.shuadan.quartz; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component public class GlodQuartz { /** * 每隔2秒执行 */ @Scheduled(cron = "*/2 * * * * ? ") public void addUserGold() { System.out.println("搞事情?"); } }
springMVC-mvc.xml添加配置声明
xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation=" http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd"
<task:annotation-driven /> <context:component-scan base-package="com.shuadan.quartz"/>