Ответ 1
EDIT: лучший ответ здесь и предполагает создание Исполнителя:
@Configuration
@EnableAsync
public class AppContext extends WebMvcConfigurationSupport {
@Bean
public Executor taskExecutor() {
return new SimpleAsyncTaskExecutor();
}
}
ПРЕДЫДУЩИЙ (все еще действительный):
Исключение NoSuchBeanDefinitionException регистрируется с серьезностью DEBUG и может быть безопасно проигнорировано. Если вы посмотрите на исходный код ScheduledAnnotationBeanPostProcessor, вы увидите, что сначала он пытается получить TaskScheduler, затем ScheduledExecutorService, а затем продолжает "возвращаться к планировщику по умолчанию":
if (this.registrar.hasTasks() && this.registrar.getScheduler() == null) {
Assert.state(this.beanFactory != null, "BeanFactory must be set to find scheduler by type");
try {
// Search for TaskScheduler bean...
this.registrar.setScheduler(this.beanFactory.getBean(TaskScheduler.class));
}
catch (NoUniqueBeanDefinitionException ex) {
throw new IllegalStateException("More than one TaskScheduler exists within the context. " +
"Remove all but one of the beans; or implement the SchedulingConfigurer interface and call " +
"ScheduledTaskRegistrar#setScheduler explicitly within the configureTasks() callback.", ex);
}
catch (NoSuchBeanDefinitionException ex) {
logger.debug("Could not find default TaskScheduler bean", ex);
// Search for ScheduledExecutorService bean next...
try {
this.registrar.setScheduler(this.beanFactory.getBean(ScheduledExecutorService.class));
}
catch (NoUniqueBeanDefinitionException ex2) {
throw new IllegalStateException("More than one ScheduledExecutorService exists within the context. " +
"Remove all but one of the beans; or implement the SchedulingConfigurer interface and call " +
"ScheduledTaskRegistrar#setScheduler explicitly within the configureTasks() callback.", ex);
}
catch (NoSuchBeanDefinitionException ex2) {
logger.debug("Could not find default ScheduledExecutorService bean", ex);
// Giving up -> falling back to default scheduler within the registrar...
}
}
}
Вы можете удалить исключение, установив хотя бы степень серьезности INFO на org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor, например
<logger name="org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor" level="INFO"/>
при использовании журнала.
Выражение cron имеет шесть полей:
second (0-59), minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (1-7, 1 = Sunday)
Синтаксис можно найти в кварцевых документах. Я не уверен в "?" потому что, хотя на странице написано
"?" символ разрешен для полей дня месяца и дня недели. Он используется для указания "нет специального значения". Это полезно, когда вам нужно указать что-то в одном из двух полей, но не в другом.
примеры на этой странице на самом деле используются? даже если другое поле равно *. IMHO все должно работать только с *, поэтому для выполнения каждой полуночи выражение должно быть
0 0 0 * * *