我在使用spring的quartz的时候碰到一个问题,我的spring配置是这么配置的
<bean 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="exampleJob" />
    <property name="cronExpression" value="0 0 6 * * ?" />
</bean>
    
    <bean id="exampleJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
  <property name="targetObject" ref="exampleBusinessObject" />
  <property name="targetMethod" value="doIt" />
</bean>
Java类是这样的public class ExampleBusinessObject { public void doIt(){
System.out.println("这是spring中的doIt方法");
}
}
但我运行的时候报错了,错误为:
Error creating bean with name 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' defined in class path resource [beans.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 [beans.xml]: Cannot resolve reference to bean 'exampleJob' while setting bean property 'jobDetail'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'exampleJob' defined in class path resource [beans.xml]: Cannot resolve reference to bean 'exampleBusinessObject' while setting bean property 'targetObject'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'exampleBusinessObject' is defined各位,帮我看看是什么问题

解决方案 »

  1.   

    问题我找到了,是缺少了对exampleBusinessObject的类的配置了,加上<bean id="exampleBusinessObject" class="com.chinova.quartz.ExampleBusinessObject"></bean>即可,但我不明白为什么spring中使用quartz进行调度任务会需要spring.jar   quartz-all-1.6.0.jar   log4j-1.2.14.jar   commons-collections.jar   jta.jar   commons-logging.jar呢?
      

  2.   

    你这个是要spring的这个东东做什么呢
      

  3.   


    楼主是否项目中的其他代码用到了jar包啊!!
      

  4.   

    没有用到,我只做了个定时任务,但需要上面的那些jar包
      

  5.   

    我不明白为什么只做个定时任务,会需要那么多的包,log4j的东西,我可以理解,spring.jar和quartz我也可以理解,但commons-collections.jar jta.jar commons-logging.jar这三个jar包是做什么用的呢?我很不理解
      

  6.   

    java就是包多,便于商业开发。
    但你也可以不用这些包,自己开发相应代码。
      

  7.   

    我吃菜放盐是因为需要盐调味,那我用spring做定时任务,这些包是干什么用的,我总要知道吧
      

  8.   

    依赖于别的东西,别人实现了自己就不需要写了 比如spring很多的方法都是用到commons的类和方法! 
    软件重用    依赖