SpringBoot 中 @Async 注释的组件/集成测试失败

问题描述

在其中一个类中包含 @Async 注释的 SpringBoot 项目中运行组件/集成测试时遇到错误

当我删除@Async 注释时,它工作正常。

我的代码如下所示:

@Configuration
@EnableAsync
public class MyAsyncConfiguration {

  @Bean
  public Executor threadPoolTaskExecutor() {
    return new ThreadPoolTaskExecutor();
  }

}

@Async 注释方法如下所示:

@Service
public class Asyncoperations {

  @Async
  public void doAsyncoperations() {
    // Some business logic here
  }
    

当我从 Postman 访问 API 时,代码完全正常。异步操作按预期异步发生,但是当我使用 mvn verify 命令运行组件/集成测试时,出现如下错误

Caused by: java.lang.IllegalStateException:Failed to introspect class [className] from ClassLoader [jdk.internal.loader.ClassLoader]

Caused by: java.lang.classFormatError: Method "$jacocoData" in class (Asyncoperations) has illegal signature

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)