我所知道的java定时任务的几种常用方式:
1、spring schedule注解的方式;
2、spring schedule配置文件的方式;
3、java类继承TimerTask;
第一种方式的实现:
1、使用maven创建spring项目,schedule在spring-context.jar的包下边,因此需要导入与之相关的包;同时,我配的是spring web项目,也同时导入了spring-web和spring-webmvc的包,如下:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>