quartz和spring结合,报空指针错误:java.lang.NullPointerException
2018-03-03 19:11
2446 查看
一 使用spring管理quartz,在启动服务器的时候,报错:
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一次,寻找值为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;
}
} 并且在application.xml的配置文件中配置: <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobFactory" ref="jobFactory" />
<property name="triggers">
<list>
<ref bean="simpleTrigger" />
</list>
</property>
</bean>2 可以尝试:
方法1. 从Spring的ApplicationContext获取JobEndConference对象。 方法2. 取消JobEndConference的本身和参数的注解,用new初始化。 来源于:https://www.cnblogs.com/yoyotl/p/5624268.html
相关文章推荐
- Quartz和Spring,Mybatis结合,读数据库空指针(NullPointerException)
- 空指针错误 java.lang.NullPointerException
- 空指针错误 java.lang.NullPointerException 浅谈
- saveAttributes 报空指针错误(java.lang.NullPointerException)
- 空指针错误 java.lang.NullPointerException 浅谈
- java.lang.NullPointerException空指针错误调试
- getActionBar()返回为空 空指针错误 Caused by: java.lang.NullPointerException
- java.lang.NullPointerException空指针错误调试
- "空指针错误 java.lang.NullPointerException "
- 空指针错误 Java.lang.NullPointerException
- 接口报java.lang.NullPointerException错误
- 在onTabSelected里面调用viewPager.setCurrentItem方法发生java.lang.NullPointerException错误
- eclipse中,junit对单个方法进行测试时空指针异常(java.lang.NullPointerException)
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- 多数据源spring 报java.lang.NullPointerException
- 在“JDI Event Dispatch”期间发生了内部错误。 java.lang.NullPointerException
- 安卓开发过程中空指针的问题Java.lang.NullPointerException
- java.lang.NullPointerException错误!!遇到过很多次..
- spring/struts异常exception starting filter struts2 java.lang.NullPointerException ..SpringObjectFacory
- 空指针问题(java.lang.NullPointerException)