Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring中TaskScheduler的NoSuchBean定义_Spring_Scheduled Tasks - Fatal编程技术网

Spring中TaskScheduler的NoSuchBean定义

Spring中TaskScheduler的NoSuchBean定义,spring,scheduled-tasks,Spring,Scheduled Tasks,我正试图用Spring安排一项任务。这是我的代码: @Service public class MyWork implements Runnable { @Override public void run() { workToDo(); } private void workToDo() { /*do it*/} } @Service public class MySchedulerInvoker { @Autowired

我正试图用Spring安排一项任务。这是我的代码:

@Service
public class MyWork implements Runnable {
    @Override
    public void run() {
        workToDo();
    }


    private void workToDo()  { /*do it*/}
}

@Service
public class MySchedulerInvoker {
    @Autowired
    private TaskScheduler scheduler;

    @Async
    public void executeTask() {
    scheduler.schedule(new MyWork(), new CronTrigger(
            "* 15 9-17 * * MON-FRI"));
}
运行时,出现以下错误:

ava.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
[...]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name     'mySchedulerInvoker ': Injection of autowired dependencies failed; nested exception is     org.springframework.beans.factory.BeanCreationException: Could not autowire field: private     org.springframework.scheduling.TaskScheduler com.infoone.siglo.GestoreNotificheCtr.scheduler; nested exception is     org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type     [org.springframework.scheduling.TaskScheduler] found for dependency: expected at least 1 bean which qualifies as     autowire candidate for this dependency. Dependency annotations: [...]
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private     org.springframework.scheduling.TaskScheduler com.infoone.siglo.GestoreNotificheCtr.scheduler; nested exception is     org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type     [org.springframework.scheduling.TaskScheduler] found for dependency: expected at least 1 bean which qualifies as     autowire candidate for this dependency. Dependency annotations: [...]

缺少什么?

在与您的
MySchedulerInvoker
相同的上下文中没有可用的
TaskScheduler
bean。您需要显示一些配置,以便有人指出原因。

嗯。。。我忘了在配置文件中添加任何关于调度程序的内容。