spring3.0后,引入了注解,因此配置显得很方便。只要配置好配置文件的命名空间,然后直接在代码中使用注解即可!
首先,配置文件的schema要加上 这两句:
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd
然后,配置namespace的别名:
xmlns:task="http://www.springframework.org/schema/task"
配置文件的头部,就配置好了。
然后是,打开定时器的开关:
<task:annotation-driven/>
最后配置扫描包路径的时候要包含你定时任务所在的包
<context:component-scan base-package="com.cnpc.framework.conf"/>
问题就得到解决了。