package cn.lz.devops.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Lazy(false)
@Component
public class TestDemo {
private static final Logger logger = LoggerFactory.getLogger(TestDemo.class);
@Scheduled(cron = "0/5 * * * * ?")
public void setTime() {
logger.debug("运行一次!!!");
}
}
@Lazy(false) 的作用是否定懒加载(懒加载是这个类在程序启动的时候不需要一起启动这个类,在用的时候才会自动初始化)
@Component 将这个类交给Spring管理。
@Scheduled(cron = "0/5 * * * * ?")