第一种,很麻烦
配置文件
<!--扫描所在包-->
<context:component-scan base-package="com.xxx.schedule"/>
<!--开启注解-->
<task:annotation-driven/>
<bean id="task" class="com.xxx.schedule.ScheduleTask"/>
<task:scheduler id="scheduler" pool-size="3" />
<task:scheduled-tasks scheduler="scheduler">
<task:scheduled ref="task" method="hello" cron="0/5 * * * * ?" />
</task:scheduled-tasks>
java类
package com.xxx