spring定时任务实现

<!-- 定义定时任务类,如果该类继承了HibernateDaoSupport,就一定要加载sessionFactory -->
	<bean id="exampleBusinessObject" class="dao.hibernate.CustomerDAOHibernateImpl">
		<property name="sessionFactory" ref="mySessionFactory"/>
	</bean>
	
	<!-- 指明定时任务执行的方法 -->
	<bean id="jobDetail"
		class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
		<property name="targetObject" ref="exampleBusinessObject" />
		<property name="targetMethod" value="scheduleTask" />
	</bean>
	
	<!-- 规定定时任务什么时候执行 -->
	<bean id="cronTrigger"
		class="org.springframework.scheduling.quartz.CronTriggerBean">
		<property name="jobDetail" ref="jobDetail" />
		<!-- 每1分钟执行一次 -->
		<property name="cronExpression" value="0 0/1 * * * ?" />
	</bean>

	<!-- 加载定时任务 -->
	<bean
		class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="triggers">
			<list>
				<ref bean="cronTrigger" />
			</list>
		</property>
	</bean>

你可能感兴趣的:(java,spring)