首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

spring quartz配备定时器

2012-09-08 
spring quartz配置定时器1.applicationContext.xml?xml version1.0 encodingUTF-8? ? ? ? ? ? ? ?

spring quartz配置定时器

1.applicationContext.xml


<?xml version="1.0" encoding="UTF-8"?> ? ? ? ? ? ? ? ? ??

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans> ??

?<!--起动Bean-->


? <bean id="test" ? ?/>

? ? ? ? ? ? ? ? ? ? ? ? </list>

? ? ? ? ? </property>

? </bean>


<!--实际的工作Bean-->

<bean id="testjobbean" />

? ? ? ?</property>

? ? ? <property name="targetMethod">

? ? ? ? ? ? ? ? ? ? <value>run</value>

? ? ?</property>

</bean>


<!--定时器设定(0/2 43 12-17 * * ?在12-17点43分,每隔2秒运行一次)-->


<bean id="cronReportTrigger" ?/>

? ? ? </property>

? ? ? <property name="cronExpression">

? ? ? ? ? ? <value>0/2 43 12-17 * * ?</value>

? ? ? </property>

</bean>

</beans>



?2.创建类 TestJobBean


public class TestJobBean{

? ? public void run() {

? ? ? ? System.out.println("run..................");

? ? }

}


3..获取bean测试:


?public static void main(String[] args) throws BeansException, FileNotFoundException, InterruptedException {

? ? ? ? BeanFactory factory = new XmlBeanFactory( ?new FileSystemResource( ? "///home/zhouxf/work/WebPro/WebContent/WEB-INF/bean.xml"));

? ? ? ? factory.getBean("test");

? ? }


?转自:http://hacker-zxf.javaeye.com/blog/296554


热点排行