в моем веб-приложении, разработанном с помощью GWT, Hibernate и Spring, я сталкиваюсь при установке bean-компонента jobClass в файле application-context.xml.
Я получаю исключение NullPointerException во время выполнения, с absenceDao
равным нулю:
Вот мой класс Java:
public class ExampleJob extends QuartzJobBean {
private AbsenceDao absenceDao;
@Override
protected void executeInternal(JobExecutionContext context)
throws JobExecutionException {
List untreatedDemands = new ArrayList();
untreatedDemands = absenceDao.getDemandsAskedNotValidated();
}
public AbsenceDao getAbsenceDao() {
return absenceDao;
}
public void setAbsenceDao(AbsenceDao absenceDao) {
this.absenceDao = absenceDao;
}
}
и вот мое application-context.xml:
classpath:internal.properties
</p>
<pre><code><!-- Configuration du crontrigger -->
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref local="exampleJob1" />
</property>
<property name="cronExpression">
<util:constant static-field="fr.web.utils.APP_VAR.CRON_EXPRESSION" />
</property>
</bean>
<bean id="jobClass" class="fr.web.utils.ExampleJob">
<property name="absenceDao" ref="absenceDao"/>
</bean>
<bean id="exampleJob1" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="fr.web.utils.ExampleJob" />
<property name="jobDataAsMap">
<map>
<entry key="timeout" value="5" />
</map>
</property>
</bean>
<!-- Bean containing all the properties of the application -->
<bean class="fr.web.utils.ApplicationProperties" id="applicationProperties" lazy-init="true" scope="singleton">
<constructor-arg index="0" value="classpath:internal.properties"/>
</bean>
<!-- Bean DAO -->
<bean abstract="true" id="abstractDao">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean class="fr.web.dao.AbsenceDao" id="absenceDao" parent="abstractDao"/>
</bean>
Я думал, что установки свойства, ссылающегося на Дао в bean-объекте jobClass, было достаточно, но, очевидно, я ошибался.
Редактировать: если я устанавливаю свойство Dao в bean-компоненте exampleJob1, я получаю эту ошибку во время выполнения:
Error 500 Error creating bean with name 'schedulerFactory' defined in class path resource [application-context.xml]:
Cannot resolve reference to bean 'cronTrigger' while setting bean property 'triggers' with key [0];
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'cronTrigger' defined in class path resource [application-context.xml]:
Cannot resolve reference to bean 'exampleJob1' while setting bean property 'jobDetail';
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'exampleJob1' defined in class path resource [application-context.xml]:
Error setting property values;
nested exception is org.springframework.beans.NotWritablePropertyException:
Invalid property 'absenceDao' of bean class [org.springframework.scheduling.quartz.JobDetailBean]:
Bean property 'absenceDao' is not writable or has an invalid setter method.
Does the parameter type of the setter match the return type of the getter?