Spring+Quartz报错,帮忙解决下!!!!!!

在xml文件中的代码如下:

 



<beans default-autowire="byName">
  <bean id="testQuartz" class="com.quartz.actions.TestQuartz"></bean>
  <bean id="scheduledReportJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    <property name="targetObject">
      <ref bean="testQuartz">
    </property>
    <property name="targetMethod">
      <value>execute</value>
    </property>
  </bean>
  <bean id="cronReportTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail">
      <ref bean="scheduledReportJobDetail">
    </property>
    <property name="cronExpression">
      <value>10,15,20,25,30,35,40,45,50,55 * * * * ?</value>
    </property>
  </bean>
  <bean id="startQuartz" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
      <list>
        <ref bean="testQuartz">
      </list>
    </property>
  </bean>
</beans>

 

TestQuartz类很简单就只在控制台打印一句话。。。。。。。。。。

 

测试类代码:

public static void main(String[] args) {
        BeanFactory factory = new XmlBeanFactory(new FileSystemResource("D:/Items/Projects/configuration/applicationContext_quartz.xml"));
        factory.getBean("startQuartz");

}

 

在运行的时候报如下错误,帮忙解决下啊

 

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'startQuartz' defined in file [D:\Items\Projects\configuration\applicationContext_quartz.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.util.ArrayList] to required type [org.quartz.Trigger[]] for property 'triggers'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [zhjb.quartz.actions.TestQuartz] to required type [org.quartz.Trigger] for property 'triggers[0]': no matching editors or conversion strategy found
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at Test.main(Test.java:9)
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.util.ArrayList] to required type [org.quartz.Trigger[]] for property 'triggers'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [zhjb.quartz.actions.TestQuartz] to required type [org.quartz.Trigger] for property 'triggers[0]': no matching editors or conversion strategy found
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1289)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1250)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    ... 9 more
Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [zhjb.quartz.actions.TestQuartz] to required type [org.quartz.Trigger] for property 'triggers[0]': no matching editors or conversion strategy found
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:124)
    at org.springframework.beans.TypeConverterDelegate.convertToTypedArray(TypeConverterDelegate.java:393)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:186)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
    ... 13 more

1个回答

我的配置如下,工作很好。
[code="java"]<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<bean name="testScheduler" class="arden.scheduler.TestScheduler" />

<bean id="jobDetail"
    class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    <property name="targetObject" ref="testScheduler" />
    <property name="targetMethod" value="doIt" />
    <property name="concurrent" value="false" />
</bean>

<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
    <!-- see the example of method invoking job above -->
    <property name="jobDetail" ref="jobDetail" />
    <!-- 10 seconds -->
    <property name="startDelay" value="10000" />
    <!-- repeat every 50 seconds -->
    <property name="repeatInterval" value="5000" />
</bean>

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
        <list>
            <ref bean="simpleTrigger" />
        </list>
    </property>
</bean>

[/code]

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐