Spring不是@Autowiring ThreadPoolExecutor

时间:2014-07-16 15:30:43

标签: java spring nullpointerexception autowired

我不确定为什么我的RunGenerator类没有拿起@Autowired RunDao对象。 RunDao Autowire在与RunGenerator完全相同的包中的其他类中被识别,但RunGenerator是其包中唯一一个在引用dao对象时返回nullpointerexception的类。

package com.web_application;

 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Controller;

@Controller
public class RunGenerator implements Runnable{

String environment;

@Autowired
RunDao rDao;

int testNumber;

public RunGenerator()
{

}
public RunGenerator(String environment)
{
    this.environment = environment;
    testNumber = getLatestTestNumber() + 1;

}
@Override
public void run() {
    for(int i = 0; i < 500; i++)
    {
        System.out.println(i + ",  " + environment);
    }

}

public int getLatestTestNumber()
{
    int testNum = rDao.findLatestTestNumber(environment);
    return testNum;
}

}

这是初始化RunGenerator的地方

package com.web_application;


import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobKey;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Controller;

import com.ThreadPoolExec;

@Controller
public class ScheduledJob extends QuartzJobBean {


String environment;
@Override
protected void executeInternal(JobExecutionContext context)
        throws JobExecutionException {

    ThreadPoolExecutor threadPoolExecutor = ThreadPoolExec.getExecutor(); 
    System.out.println(threadPoolExecutor.getPoolSize());
    JobKey key = context.getJobDetail().getKey();
    String enviro = key.getGroup();
    threadPoolExecutor.execute(new RunGenerator(enviro));


}

}

这是stacktrace

java.lang.NullPointerException: null
at com.web_application.RunGenerator.getLatestTestNumber(RunGenerator.java:38)
at com.web_application.RunGenerator.<init>(RunGenerator.java:24)
at com.web_application.ScheduledJob.executeInternal(ScheduledJob.java:33)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:113)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)

0 个答案:

没有答案