春の休止状態プロジェクトに取り組んでいます。データベースに接続して、quartzjob から値を取得しようとしています。しかし、ヌルポインタ例外が発生しています。ApplicationContext オブジェクトを使用して、データベースに接続している Bean を取得しようとしたときに、他の方法を実行できないのはなぜですか
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>