Tag: 石英调度器

使用Spring创建Scheduler Bean时发生NullPointerException

我想用Spring来创建一个调度器。 @Configuration @EnableScheduling public class MyScheduler { @Autowired MyBusinessService businessService; @Scheduled(cron = "* * * * * *") public void myCronMethod() { } } 在应用程序启动过程中,出现以下错误: java.lang.NullPointerException at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.resolveSchedulerBean(ScheduledAnnotationBeanPostProcessor.java:281) at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.finishRegistration(ScheduledAnnotationBeanPostProcessor.java:221) at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.onApplicationEvent(ScheduledAnnotationBeanPostProcessor.java:200) at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.onApplicationEvent(ScheduledAnnotationBeanPostProcessor.java:94) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:383) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:337) at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:882) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068) at […]

如何用Quartz调用现有对象的方法?

我有一个对象,很好地配置了所有需要做的工作。 如果我可以每天一次地调用run() ,我的生活将会完成。 要清楚,我知道如何创建一个时间表和触发器。 但是所有调度方法都需要JobDetail,它需要创建一个新的类实例。 我如何使用我拥有的那个? 总之,没有一个很好的方式,使用Quartz调用我的对象的方法吗?