请问在Spring boot 练习的时候 让这个依赖注入生效

业余编程人士 发布于 2017/06/15 16:44
阅读 139
收藏 0
	private final  ScheduledThreadPoolExecutor exe = new ScheduledThreadPoolExecutor(50);
	public static void main(String[] args)  {
		SpringApplication.run(ProcessCenter.class, args);
	}
	@Bean
	public CommandLineRunner run()  {
		return (x) -> {
			exe.scheduleAtFixedRate(new DetailedGNSSDataProcessing(), 0, 5, TimeUnit.MINUTES);
		};	
	}
@Component
public class DetailedGNSSDataProcessing implements Runnable {

	public DetailedGNSSDataProcessing() {
	}

	private EnforcementRecordService enforcementRecordService;
	private ErrorNotificationService errorNotificationService;

	@Resource
	public void setEnforcementRecordService(EnforcementRecordService enforcementRecordService) {
		this.enforcementRecordService = enforcementRecordService;
	}
	@Resource
	public void setErrorNotificationService(ErrorNotificationService errorNotificationService) {
		this.errorNotificationService = errorNotificationService;
	}

	/**
	 * Detailed GNSS Data processing start to handling...
	 */
	private void process() throws Exception {  // 这里是null,没有注入成功
		List<EnfEbosEnforcementRecord> eefLists = enforcementRecordService.getAllEbos("GS");
}

@Override
	public void run() {
			try {
				process();
			} catch (Exception e) {
				e.printStackTrace();
			}
	}

java.lang.NullPointerException
    at sg.gov.lta.erp2.enf.ebos.action.DetailedGNSSDataProcessing.process(DetailedGNSSDataProcessing.java:39)
    at sg.gov.lta.erp2.enf.ebos.action.DetailedGNSSDataProcessing.run(DetailedGNSSDataProcessing.java:67)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

我想问的是 我明明写了@Resource 还是没有注入 换成@Autowire 还是没有注入,是不是先线程池里new 这个对象 不能完成注入? 如果我想让Spring自动帮我管理注入 我应该怎么做这部分

加载中
返回顶部
顶部