xmlns add the following content,
- xmlns:task="http://www.springframework.org/schema/task"
Then add the following to xsi:schemaLocation,
- http://www.springframework.org/schema/task
- http://www.springframework.org/schema/task/spring-task-3.1.xsd
Finally, our task task scan annotation
- <task:annotation-driven/>
My config scan location is:
- <context:annotation-config/>
- <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
- <context:component-scan base-package="com.test"/>
What is scanned is the content under packages such as com.test,
The interface and implementation are required below (my java files are all under the package of com.test)
- public interface IMyTestService {
- public void myTest();
- }
- @Component //import org.springframework.stereotype.Component;
- public class MyTestServiceImpl implements IMyTestService {
- @Scheduled(cron="0/5 * * * * ? ") //Execute every 5 seconds
- @Override
- public void myTest(){
- System.out.println("进入测试");
- }
- }