@Configuration(value = "springConfigContext")
@EnableAspectJAutoProxy
@EnableTransactionManagement
@ApplicationScoped
@EnableAsync
@EnableScheduling
@ComponentScan(basePackages = {"com", })
@ImportResource({ "classpath:springBeans.xml" })
@PropertySources({ @PropertySource("classpath:/META-INF/my_file_properties.properties") })
public class SpringConfigContext extends AnnotationConfigApplicationContext implements BeanFactory{
@Bean
public MethodInvokingJobDetailFactoryBean methodInvokingJobDetailFactoryBean(){
//my code
}
@Bean
public SimpleTriggerFactoryBean simpleTriggerFactoryBean(){
//my code
}
@Bean
public JobDetailFactoryBean jobDetailFactoryBean(){
//my code
}
@Bean
public CronTriggerFactoryBean cronTriggerFactoryBean() throws ParseException{
//my code
}
@Bean(name = "springQuartzScheduler")
public SchedulerFactoryBean schedulerFactoryBean() throws Exception{
SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
CronTrigger trigger = cronTriggerFactoryBean().getObject();
scheduler.setTriggers(simpleTriggerFactoryBean().getObject(), trigger);
Properties propertie = new Properties();
propertie.setProperty("org.quartz.threadPool.threadCount", "3");
propertie.setProperty("org.quartz.threadPool.threadPriority", "3");
scheduler.setQuartzProperties(propertie);
scheduler.setOverwriteExistingJobs(true);
scheduler.setApplicationContext(this);
scheduler.start();
return scheduler;
}
}
the first build for method public SchedulerFactoryBean schedulerFactoryBean() the second build for other Class, Spring i'm think!
my config properties for Quartz are:
org.quartz.scheduler.skipUpdateCheck=true
org.quartz.scheduler.instanceName=schedulerFactoryBean
org.quartz.scheduler.jobFactory.class=org.springframework.scheduling.quartz.AdaptableJobFactory
org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount=5
org.quartz.threadPool.threadPriority=5
I'm try to use same name of the bean "springQuartzScheduler" or schedulerFactoryBean but does't work.
How parameterize to use only one factory?
答案 0 :(得分:0)
我发现问题并解决了,当我删除一个用于监控我的项目的javamelody, net.bull.javamelody.MonitoringFilter 时在生产中。如果你有另一个神器相同的命题,应该负责创建一个新工厂石英的新实例
所以如果你有一个类似的问题 2 JobFactory Bean ,评估他们可能负责生成工厂Quartz的多个实例的工件,因为Quartz没有工厂bean单例用于VM,它是在调用时创建一个新工厂,具有相同的文件quartiz.properties属性,但在其他上下文中使用时。
怎么发现问题?将logback置于模式日志跟踪中,这样你就会看到调用的工厂Quartz,删除索引或调整以便它们使用相同的工厂