我想禁用@EnableAsync
当我运行集成测试时。
我试图覆盖带有注释的配置文件@EnableAsync
在我的测试包中有一个同名的类,但它不起作用。
在本主题中:是否可以在集成测试期间禁用Spring的@Async? https://stackoverflow.com/questions/42134750/is-it-possible-to-disable-springs-async-during-integration-test
我已经看到:
您可以...创建测试配置或简单地使用 SyncTaskExecutor 覆盖任务执行器
但我不明白该怎么办。
有什么建议吗?谢谢
您链接的主题确实提供了一个很好的解决方案。
创建一个SyncTaskExecutor
对于测试,请确保您实际上有一个用于 spring 上下文的测试配置类。请参阅 Spring 文档:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html
在这个配置类中添加一个新的bean:
@Bean
@Primary
public TaskExecutor taskExecutor() {
return new SyncTaskExecutor();
}
应该这样做!
注意不要在你的实时配置中创建这个 bean!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)