程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> spring定時任務-Spring 定時任務 在執行方法時報空指針

spring定時任務-Spring 定時任務 在執行方法時報空指針

編輯:編程綜合問答
Spring 定時任務 在執行方法時報空指針

定時任務的xml:


com.boco.auto.AutoIPV6BusinessAlarmStatisticsReport







0 30 3 * * ?


Spring注入:
class="com.boco.web.struts.action.report.ReportCommonActionPipeRes"
parent="baseAction">





















<!-- add liuhuipeng -->





class="com.boco.alarm.service.impl.VendorFaultReportServiceImpl">













定時任務:
public class AutoAlarmStatisticsReport implements Job{
static Logger logger = Logger.getLogger(AutoAlarmStatisticsReport.class) ;
private ReportCommonActionPipeRes pipeResAction;

@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
    logger.info("+++進入定時任務。+++");
    generateReport();
}
public void generateReport(){
    logger.info("modelName=AlarmStatistics");
    pipeResAction = (ReportCommonActionPipeRes)StartupApp.getInstance().
    getAppContext().getBean("reportpiperesource");
    String modelName = "IPV6BusinessAlarmStatistics";
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String today = sdf.format(date);
    this.pipeResAction.insertBusinessNEStatistics(modelName);
    //insertBusinessNEStatistics(modelName);
}

}
調用此方法:
public boolean insertBusinessNEStatistics(String modelName){
boolean isOk = false;
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String createDate = sdf.format(date);
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date datestart = new Date();

String startDateString="";
startDateString= sdf1.format(datestart);
List Allist = new ArrayList();
String informixSql = statementManagementBean.getStatementByName(modelName.trim());
Map parameterMap = new HashMap();

    if((null == informixSql)||informixSql.equalsIgnoreCase("no such table")){
        return isOk;
    }else{
        String[] sql_Array = informixSql.split(";");
        List<Map> dataList = new ArrayList<Map>();
        for(String sql : sql_Array){
            if(sql != null && sql.trim().length() > 0){
                if(modelName.equalsIgnoreCase("AlarmStatistics")){
                    String procName = "{call pro_alarm_trans_counteveryday()}";
                    boolean isInsertflag= false;
                    //測試:
                    isInsertflag = true;
                //  try {
                //      isInsertflag = vendorfaultService.insertIPV6AlarmCount(procName);
                //      logger.info("++獲得告警標識:++"+isInsertflag);
                //  } catch (Exception e) {
                        // TODO: handle exception
                //      logger.error("error 錯誤的信息", e);
                //  }
                    if(isInsertflag == true){
                        try{
                            dataList = vendorfaultService.queyAlarm(parameterMap, sql.trim(), false);
                        }catch(Throwable t){
                            logger.error("error 錯誤的信息", t);
                        }
                    }else{
                        return isInsertflag;
                    }
                }else{
                    //dataList = reportCommonDao.commonQuery(sql.trim(), parameterMap);
                    dataList = reportCommonDao.commonQuery(sql.trim(), parameterMap);
                }

            }
        }

        isOk = true;
    }
    return isOk;    
}

最佳回答:


自己找到了,原來這裡面是雙配置。自己就注入了一個。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved