spring - 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
解决方案
推荐阅读
- p2 - Eclipse p2 NoSuchAlgorithmException:找不到 1.2.840.113549.1.1.11 的算法
- javascript - 图像仅在给定链接时显示,而不是路径
- android - Android Blackberry:如何使用黑莓访问在应用程序内呈现视图
- java - Gson - 为什么我的循环会弄乱我的 json 文件?
- java - 为什么我的 JAR 文件不运行?(IntelliJ、JavaFX、Maven)
- javascript - 反应 setState 不更新状态
- r - 使用 XML2 将 XML 转换为数据帧——SDMX 案例
- fabricjs - 如果 FabricJS 对象被代码移动,鼠标选择似乎不起作用
- r - 如何计算R中唯一值的总和
- c - PRQA QAC 在遇到#error 指令后终止