About Spring when you use multiple Quatz profiles to configure a scheduled task, only one of the files is valid for the taskProblem description
Work with spring and Quatz to implement timer triggering some scheduled tasks, originally written in a configuration file. After splitting the different business logic into two files, it was found that each time the spring container was started, only the scheduled tasks configured in one of the files were executed again, and the other did not.
Solution Solutions
The solution was found on StackOverflow through Google, but the reason was simple. In the case where multiple scheduler are configured in the Spring container, each scheduler must be given a name and ID, otherwise multiple scheduler configured with a singleton will overwrite each other, causing only one scheduler configuration to run.
So make the following changes to the configuration file:
<beans> ...... 前面关于执行类的定义这里省略 ...... <!-- Scheduler配置 如果将lazy-init=‘false‘那么容器启动就会执行调度程序,如果配置了多个,必须分配id,且每个Scheduler id不同 --> <bean id="startQuertz" lazy-init="false" singleton="true" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <!--name也必须设置,保证各Scheduler之间不同即可--> <property name="schedulerName" value="defaultScheduler"/> <property name="triggers"> <list> <ref bean="doTime"/> </list> </property> </bean></beans>
Resources
- StackOverflow: "Using the schedulers in one Spring context"
About Spring when you use multiple Quatz profiles to configure a scheduled task, only one of the files is valid for the task