Spring task II

前面的設定採原了傳統的 spring 設定檔的方式進行 , 但是 , 也可以簡化成使用 annotation 的方式.

但是 , 要增加額外的 jar 檔 aopalliance-.jar 不增加此檔  在啟動時 會出現

java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice

並且在  spring 設定檔中  , 增加下列兩行設定

<task:annotation-driven />
<bean id=”runScheduler2″ class=”com.tcg.task.OtherTask” />

package com.tcg.task;
 
import org.springframework.scheduling.annotation.Scheduled;
 
public class OtherTask {
 
 @Scheduled(fixedRate = 2000)
 public void m1(){
 System.out.println("OtherTask..m1..");
 }
  
 @Scheduled(fixedDelay = 2000)
 public void m2(){
 System.out.println("OtherTask..m2..");
 }
  
}