0

我正在尝试使用 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: [...]

少了什么东西?

4

1 回答 1

1

TaskScheduler与您的MySchedulerInvoker. 您需要显示一些配置,以便有人指出原因。

于 2013-02-19T02:35:20.350 回答