如何在 Spring 中覆盖默认的 AsyncConfigurer(摆脱“可能只存在一个配置器”)

h22*_*h22 5 java spring asynchronous spring-boot

我必须让我自己的 Executor 使用 Spring @Async 注释。为此,我按照以下方式编写了课程

@Configuration
@EnableAsync
public class ConnectedThreads implements AsyncConfigurer {

  @Override
  public Executor getAsyncExecutor() {
    return ...
Run Code Online (Sandbox Code Playgroud)

当我尝试使用此类运行 Spring Boot 应用程序时,应用程序崩溃了

Caused by: java.lang.IllegalStateException: Only one AsyncConfigurer may exist
    at org.springframework.scheduling.annotation.AbstractAsyncConfiguration.setConfigurers(AbstractAsyncConfiguration.java:68)
Run Code Online (Sandbox Code Playgroud)

项目中没有其他配置器。这是一个非常小的项目,我可以完全控制它。我自己怀疑自定义配置器可能只是与默认配置器冲突。

有没有可能对 Spring 说这是我需要的配置器,它不应该寻找任何其他配置器?