zoukankan      html  css  js  c++  java
  • 工具类中使用service

    (1)工具类 SpringUtil.java

    package com.googosoft.until;
    
    import org.springframework.beans.BeansException;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.ApplicationContextAware;
    import org.springframework.stereotype.Component;
    
    @Component
    public class SpringUtil implements ApplicationContextAware {
        private static ApplicationContext appCtx;
    
        @Override
        public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
            appCtx = applicationContext;
        }
    
        public static ApplicationContext getApplicationContext() {
            return appCtx;
        }
    
        public static Object getBean(String beanName) {
            return appCtx.getBean(beanName);
        }
    }

    注:类上要加@Component注解,否则会报空指针

    (2)使用

    package com.googosoft.job;
    
    import javax.annotation.Resource;
    import org.quartz.Job;
    import org.quartz.JobDataMap;
    import org.quartz.JobExecutionContext;
    import org.quartz.JobExecutionException;
    import com.googosoft.service.QualityEvaluationService;
    import com.googosoft.until.SpringUtil;
    import com.googosoft.util.PageData;
    
    /**
     * @author songyan
     * @date 2020年3月31日 下午1:51:33
     * @desc 作业
     */
    public class EvaluationPlanJob implements Job {
        
        @Resource
        private QualityEvaluationService service = (QualityEvaluationService) SpringUtil.getBean("qualityEvaluationService");
    
        @Override
        public void execute(JobExecutionContext context) throws JobExecutionException {
           JobDataMap data = context.getJobDetail().getJobDataMap();
            PageData pd = new PageData();
            pd.put("GID", data.get("GID"));
            pd.put("DBMETAGID", data.get("DBMETAGID"));
            service.runEvaluationPlanList(pd);
        }
    
    }

    (3)关键代码:

    1)使用Resource注解

    2)beanName:service类名首字母小写

  • 相关阅读:
    Linux中的计算器(bc)
    在Linux中显示日历(cal)
    在Linux中显示日期(date)
    Linux中的注销当前用户
    Linux中的提示符
    在Linux中启动X Window
    硬盘知识
    划分Linux分区
    Linux中的关机
    hdu4424 Conquer a New Region 并查集/类似最小生成树
  • 原文地址:https://www.cnblogs.com/excellencesy/p/12624322.html
Copyright © 2011-2022 走看看