I hope this article will be helpful for you to use spring @ Scheduled annotations to execute Scheduled tasks.
Java
ApplicationContext. xml configuration:
Add a namespace:
| The Code is as follows: |
Copy code |
|
Xmlns: task = "http://www.springframework.org/schema/task"
Xsi: schemaLocation ="
Http://www.springframework.org/schema/task
Http://www.springframework.org/schema/task/spring-task-3.0.xsd"
<! -- Timer switch -->
<Task: annotation-driven/> |
The above is the basic configuration of applicationContext. xml. The following is the configuration in the class.
Add annotation to the class:
The implementation class must have the annotation @ Component of the Component.
| The Code is as follows: |
Copy code |
|
@ Component
Public class MyTestServiceImpl implements IMyTestService {
@ Scheduled (cron = "0/5 ****? ") // Execute once every 5 seconds
@ Override
Public void myTest (){
System. out. println ("go to test ");
} |
}