Kaynağa Gözat

重构调度服务注入方式

xueli.xue 9 yıl önce
ebeveyn
işleme
0f0906eeaf

+ 16 - 16
xxl-job-admin/src/main/java/com/xxl/job/core/util/DynamicSchedulerUtil.java Dosyayı Görüntüle

8
 import java.util.Map;
8
 import java.util.Map;
9
 import java.util.Set;
9
 import java.util.Set;
10
 
10
 
11
-import javax.annotation.Resource;
12
-
13
 import org.quartz.CronScheduleBuilder;
11
 import org.quartz.CronScheduleBuilder;
14
 import org.quartz.CronTrigger;
12
 import org.quartz.CronTrigger;
15
 import org.quartz.Job;
13
 import org.quartz.Job;
27
 import org.quartz.impl.triggers.CronTriggerImpl;
25
 import org.quartz.impl.triggers.CronTriggerImpl;
28
 import org.slf4j.Logger;
26
 import org.slf4j.Logger;
29
 import org.slf4j.LoggerFactory;
27
 import org.slf4j.LoggerFactory;
28
+import org.springframework.beans.BeansException;
30
 import org.springframework.beans.factory.InitializingBean;
29
 import org.springframework.beans.factory.InitializingBean;
30
+import org.springframework.context.ApplicationContext;
31
+import org.springframework.context.ApplicationContextAware;
31
 import org.springframework.util.Assert;
32
 import org.springframework.util.Assert;
32
 
33
 
33
 import com.xxl.job.client.util.JacksonUtil;
34
 import com.xxl.job.client.util.JacksonUtil;
39
  * base quartz scheduler util
40
  * base quartz scheduler util
40
  * @author xuxueli 2015-12-19 16:13:53
41
  * @author xuxueli 2015-12-19 16:13:53
41
  */
42
  */
42
-public final class DynamicSchedulerUtil implements InitializingBean {
43
+public final class DynamicSchedulerUtil implements ApplicationContextAware, InitializingBean {
43
     private static final Logger logger = LoggerFactory.getLogger(DynamicSchedulerUtil.class);
44
     private static final Logger logger = LoggerFactory.getLogger(DynamicSchedulerUtil.class);
44
     
45
     
45
-    // xxlJobLogDao
46
-    public static IXxlJobLogDao xxlJobLogDao;
47
-    @Resource
48
-    public void setXxlJobLogDao(IXxlJobLogDao xxlJobLogDao) {
49
-		DynamicSchedulerUtil.xxlJobLogDao = xxlJobLogDao;
50
-	}
51
-    // xxlJobInfoDao
52
-    public static IXxlJobInfoDao xxlJobInfoDao;
53
-    @Resource
54
-    public void setXxlJobInfoDao(IXxlJobInfoDao xxlJobInfoDao) {
55
-		DynamicSchedulerUtil.xxlJobInfoDao = xxlJobInfoDao;
56
-	}
57
-    
58
     // Scheduler
46
     // Scheduler
59
     private static Scheduler scheduler;
47
     private static Scheduler scheduler;
60
     public static void setScheduler(Scheduler scheduler) {
48
     public static void setScheduler(Scheduler scheduler) {
61
 		DynamicSchedulerUtil.scheduler = scheduler;
49
 		DynamicSchedulerUtil.scheduler = scheduler;
62
 	}
50
 	}
51
+    
52
+    // xxlJobLogDao、xxlJobInfoDao
53
+    public static IXxlJobLogDao xxlJobLogDao;
54
+    public static IXxlJobInfoDao xxlJobInfoDao;
63
 
55
 
56
+    @Override
57
+	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
58
+		DynamicSchedulerUtil.xxlJobLogDao = applicationContext.getBean(IXxlJobLogDao.class);
59
+		DynamicSchedulerUtil.xxlJobInfoDao = applicationContext.getBean(IXxlJobInfoDao.class);
60
+	}
61
+    
64
 	@Override
62
 	@Override
65
     public void afterPropertiesSet() throws Exception {
63
     public void afterPropertiesSet() throws Exception {
66
         Assert.notNull(scheduler, "quartz scheduler is null");
64
         Assert.notNull(scheduler, "quartz scheduler is null");
67
         logger.info(">>>>>>>>> init quartz scheduler success.[{}]", scheduler);
65
         logger.info(">>>>>>>>> init quartz scheduler success.[{}]", scheduler);
66
+       
68
     }
67
     }
69
 	
68
 	
70
 	// getJobKeys
69
 	// getJobKeys
266
         return result;
265
         return result;
267
     }
266
     }
268
 
267
 
268
+
269
 }
269
 }

+ 4 - 0
xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoConcurrentJobBean.java Dosyayı Görüntüle

6
 
6
 
7
 import com.xxl.job.service.job.LocalNomalJobBean;
7
 import com.xxl.job.service.job.LocalNomalJobBean;
8
 
8
 
9
+/**
10
+ * demo job bean for no-concurrent
11
+ * @author xuxueli 2016-3-12 14:25:14
12
+ */
9
 @DisallowConcurrentExecution	// 串行;线程数要多配置几个,否则不生效;
13
 @DisallowConcurrentExecution	// 串行;线程数要多配置几个,否则不生效;
10
 public class DemoConcurrentJobBean extends LocalNomalJobBean {
14
 public class DemoConcurrentJobBean extends LocalNomalJobBean {
11
 
15
 

+ 4 - 0
xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoNomalJobBean.java Dosyayı Görüntüle

7
 
7
 
8
 import com.xxl.job.service.job.LocalNomalJobBean;
8
 import com.xxl.job.service.job.LocalNomalJobBean;
9
 
9
 
10
+/**
11
+ * demo job bean for concurrent
12
+ * @author xuxueli 2016-3-12 14:25:57
13
+ */
10
 public class DemoNomalJobBean extends LocalNomalJobBean {
14
 public class DemoNomalJobBean extends LocalNomalJobBean {
11
 	private static Logger Logger = LoggerFactory.getLogger(DemoNomalJobBean.class);
15
 	private static Logger Logger = LoggerFactory.getLogger(DemoNomalJobBean.class);
12
 	
16