关于Failed to convert property value of type [org.quartz.impl.StdScheduler] to required type [org.springframework.scheduling.quartz.SchedulerFactoryBean
在一个业务类有下列属性
private SchedulerFactoryBeanscheduler; public SchedulerFactory BeangetScheduler() { return scheduler; } public void setScheduler(SchedulerFactoryBean scheduler) { this.scheduler = scheduler; }
用spring 进行装配:
<property name="scheduler"> <ref bean="schedulerFactoryBean" /> </property> </bean> <bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"/>
启动时候报:Failed to convert property value of type [org.quartz.impl.StdScheduler] to required type [org.springframework.scheduling.quartz.SchedulerFactoryBean异常
解决方案:
SchedulerFactoryBean 这个bean
<bean id="Scheduler" lazy-init="false" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean" >
</bean>
它是一个工厂bean,得到的不是它本身,而是它负责创建的org.quartz.impl.StdScheduler对象 ,
所以属性需要修改:
private StdScheduler scheduler; public StdScheduler getScheduler() { return scheduler; } public void setScheduler(StdScheduler scheduler) { this.scheduler = scheduler; }
持续学习、持续收获才能带来持续的满足和快乐!