quartzとspringを組み合わせて、空のポインタエラーを報告します:java.lang.Null PointerException
2040 ワード
1 springを使用してquartzを管理し、サーバを起動するときにエラーを報告します.
二 ソリューション:
空ポインタエラーは主にspring管理注入に変数が渡されていないため、このような問題に対して、まず、点を折ってdebugを1回行い、nullの値を持つ変数を探して修正することができる.spring管理quartzを使用する場合、空ポインタ異常が発生すると、解決策:
1.SchedulerでJobFactoryをカスタマイズしてみる
アプリケーション.xmlのプロファイルで構成します.
2試してみることができます.
方法1.SpringのApplicationContextからJobEndConferenceオブジェクトを取得する.
方法2.JobEndConferenceの自身とパラメータの注釈を取り消し、newで初期化する.
ソース:https://www.cnblogs.com/yoyotl/p/5624268.html
13:39:09,448 ERROR JobRunShell:211 - Job DEFAULT.promotionJob threw an unhandled Exception:
java.lang.NullPointerException
at cn.itcast.bos.quartz.PromotionJob.execute(PromotionJob.java:23)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
13:39:09,453 ERROR ErrorLogger:2425 - Job (DEFAULT.promotionJob threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NullPointerException]
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: java.lang.NullPointerException
at cn.itcast.bos.quartz.PromotionJob.execute(PromotionJob.java:23)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
... 1 more
二 ソリューション:
空ポインタエラーは主にspring管理注入に変数が渡されていないため、このような問題に対して、まず、点を折ってdebugを1回行い、nullの値を持つ変数を探して修正することができる.spring管理quartzを使用する場合、空ポインタ異常が発生すると、解決策:
1.SchedulerでJobFactoryをカスタマイズしてみる
@Service("jobFactory")
public class JobFactory extends AdaptableJobFactory {
@Autowired
private AutowireCapableBeanFactory capableBeanFactory;
@Override
protected Object createJobInstance(TriggerFiredBundle bundle)
throws Exception {
Object jobInstance = super.createJobInstance(bundle);
capableBeanFactory.autowireBean(jobInstance);
return jobInstance;
}
}
アプリケーション.xmlのプロファイルで構成します.
2試してみることができます.
方法1.SpringのApplicationContextからJobEndConferenceオブジェクトを取得する.
方法2.JobEndConferenceの自身とパラメータの注釈を取り消し、newで初期化する.
ソース:https://www.cnblogs.com/yoyotl/p/5624268.html