Springboot 自带的二个注解是: @EnableScheduling @Component
@EnableScheduling 是放在Springboot main方法 类上面,通过它进行加载,找到加了@Component注解的方法,下面是代码!
1.先引入jar包
<!--定时器依赖jar-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
2.在Main方法加入@EnableScheduling 这个注解
/*定时器注解*/
@EnableScheduling
@SpringBootApplication
public class GunsApplication {
private final static Logger logger = LoggerFactory.getLogger(GunsApplication.class);
public static void main(String[] args) {
SpringApplication.run(GunsApplication.class, args);
logger.error("GunsApplication is success!");
}
}
3.在你需要定时查询的方法上加入@Component注解
package com.stylefeng.guns.modular.system.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng