spring+quartz往task类内部传入参数

用的spring,需要在XML里面往JobDetailBean注入一个org.quartz.JobDataMap作为参数.在类里面可以直接取出来.(如果不用spring,可以直接配置job-data-map)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
< bean  name = "testDataMap"  class = "org.quartz.JobDataMap" >
     < constructor-arg >
         < map >
             < entry  key = "PARAM1"  value = "参数1" ></ entry >
             < entry  key = "PARAM2"  value = "参数2" ></ entry >
             < entry  key = "PARAM3"  value = "参数3" ></ entry >
         </ map >
     </ constructor-arg >
</ bean >
     
< bean  name = "jobDetail1"  class = "org.springframework.scheduling.quartz.JobDetailBean" >
     < property  name = "jobClass" >
         < value >
             com.test.quartzforcz.sendTask
         </ value >
     </ property >
     < property  name = "jobDataMap" >
         < ref  bean = "testDataMap"  />
     </ property >
</ bean >

在Job类中的 executeInternal(JobExecutionContext context) 中这样取出:

?
1
2
JobDataMap dataMap = context.getJobDetail().getJobDataMap();
logger.info( "PARAM1:"  + dataMap.getString( "PARAM1" ));

你可能感兴趣的:(spring,quartz,参数)