在我的 Spring MVC 项目中有一个 Quartz 调度程序,它一次运行两次如何修复它并一次执行一次。我的 web Initializer 类在哪里,
@WebListener
public class QuartzListener extends QuartzInitializerListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
super.contextInitialized(sce);
ServletContext ctx = sce.getServletContext();
StdSchedulerFactory factory = (StdSchedulerFactory) ctx.getAttribute(QUARTZ_FACTORY_KEY);
try {
Scheduler scheduler = factory.getScheduler();
JobDetail jobDetail = JobBuilder.newJob(TestJob.class).build();
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("simple").withSchedule(
CronScheduleBuilder.cronSchedule("0 0/1 * 1/1 * ? *")).startNow().build();
scheduler.scheduleJob(jobDetail, trigger);
scheduler.start();
} catch (Exception e) {
ctx.log("There was an error scheduling the job.", e);
}
}
}
和测试班,
public class TestJob implements Job {
@Override
public void execute(final JobExecutionContext ctx) throws
JobExecutionException {
System.out.println("Executing Job");
}
}
和 web 初始化器类,如,
public class WebAppInitializer extends
AbstractAnnotationConfigDispatcherServletInitializer{
@Override
protected Class<?>[] getRootConfigClasses(){
return new Class[]{WebSecurityConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses(){
return new Class[]{WebAppConfig.class, HibernateConfiguration.class};
}
@Override
protected String[] getServletMappings(){
return new String[]{"/"};
}
}
我的 WebConfig 是,
@Configuration
@EnableWebMvc
@ComponentScan(basePackages="com.neron")
public class WebAppConfig extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver resourceViewResolver(){
ResourceBundleViewResolver viewResolver = new
ResourceBundleViewResolver();
viewResolver.setOrder(0);
viewResolver.setBasename("views");
return viewResolver;
}
............
...............
在这里我每分钟得到两次“执行工作”,但我每分钟只想要一次“执行工作”。 任何人都可以解决吗?提前致谢!
慕森卡
相关分类