我正在尝试使用 Web 套接字和@Async
任务。
所以我创建了2个配置类:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig {
}
@Configuration
@EnableAsync
public class AsyncConfiguration {
}
我还有一个服务注入AsyncTaskExecutor
:
@Service
public class MyService {
@Autowired
private AsyncTaskExecutor asyncTaskExecutor;
}
在此之后,我的应用程序无法启动,并报告此错误:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field asyncTaskExecutor in mypackage.MyService required a bean of type 'org.springframework.core.task.AsyncTaskExecutor' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
The following candidates were found but could not be injected:
- Bean method 'applicationTaskExecutor' in 'TaskExecutionAutoConfiguration' not loaded because @ConditionalOnMissingBean (types: java.util.concurrent.Executor; SearchStrategy: all) found beans of type 'java.util.concurrent.Executor' clientInboundChannelExecutor, clientOutboundChannelExecutor, brokerChannelExecutor
- Bean method 'taskScheduler' in 'TaskSchedulingAutoConfiguration' not loaded because @ConditionalOnBean (names: org.springframework.context.annotation.internalScheduledAnnotationProcessor; SearchStrategy: all) did not find any beans named org.springframework.context.annotation.internalScheduledAnnotationProcessor
Action:
Consider revisiting the entries above or defining a bean of type 'org.springframework.core.task.AsyncTaskExecutor' in your configuration.
我该如何解决这个问题?