Create your Job execution class
@Component
public class ScheduledTasks {
public void performService() {}
Create a scheduling configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd">
<!-- Spring's scheduling support -->
<task:scheduled-tasks scheduler="taskScheduler">
<task:scheduled ref="cronService" method="performService" cron="0 */2 * * * *"/>
</task:scheduled-tasks>
<!-- The bean that does the actual work -->
<bean id="cronService" class="your.package.job.ScheduledTasks" />
<!-- Defines a ThreadPoolTaskScheduler instance with configurable pool size. -->
<task:scheduler id="taskScheduler" pool-size="1"/>
</beans>
Import this file to spring-config xml file:
<beans>
<!-- Scheduling config -->
<import resource="scheduling.xml" />
...
</beans>