上午在春季休眠项目上工作 我正试图连接到数据库并从quartzjob获取值。但我得到一个空指针异常。我了when试图使用的ApplicationContext对象,并把它连接到了database.why豆我不能做其他方式空指针异常石英与弹簧集成
public class JobScheduler extends QuartzJobBean {
@Autowired
private SourceDaoImpl sourceDao;
@Override
protected void executeInternal(JobExecutionContext arg0)
throws JobExecutionException {
Client client = new Client();
client.setClientKey(300);
sourceDao.getSourceByClient(client); **//error**
}
public SourceDaoImpl getSourceDao() {
return sourceDao;
}
public void setSourceDao(SourceDaoImpl sourceDao) {
this.sourceDao = sourceDao;
}
}
这是我的applicationContext.xml
<!-- scheduler -->
<bean id="jobScheduler" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.dca.scheduling.JobScheduler" />
<property name="jobDataAsMap">
<map>
<entry key="timeout" value="5" />
</map>
</property>
</bean>
<bean id="cronTriggerjobScheduler" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobScheduler" />
<property name="cronExpression" value="0/10 * * * * ?" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="jobScheduler" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="cronTriggerjobScheduler" />
</list>
</property>
</bean>
<bean id="jobClass"
class="com.dca.scheduling.JobScheduler">
</bean>
这是异常
ERROR 04-06 07:22:55,009 - Job DEFAULT.jobScheduler threw an unhandled Exception:
java.lang.NullPointerException
at com.dca.scheduling.JobScheduler.executeInternal(JobScheduler.java:21)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)
at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
ERROR 04-06 07:22:55,010 - Job (DEFAULT.jobScheduler 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:227)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: java.lang.NullPointerException
at com.dca.scheduling.JobScheduler.executeInternal(JobScheduler.java:21)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)
at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
... 1 more
hibernate.xml
<bean id="sourceInstanceDao" class="com.dca.dao.impl.SourceInstanceDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
我看不到配置来连接dao类。 –
它在那里我没有显示它在一个hibernatecontex.xml中,并且包含该文件到ApplicationContext.xml中 – jos
请张贴该文件 –