是否可以在集成测试期间禁用Spring的@Async?

时间:2017-02-09 10:53:06

标签: spring cucumber-java

我有一个用@Async注释的方法

@Async public void createArticles(long Id){}

但我只是尝试对该方法进行黄瓜测试。是否可以同步测试它?

1 个答案:

答案 0 :(得分:1)

创建异步配置类:

@Configuration
@EnableAsync
@ConditionalOnProperty(name = "async.enabled", havingValue = "true")
public class SpringAsyncConfig {
    // Your configuration here
}

如果仅配置值@ConditionalOnPropertyasync.enabled,则注释true将创建此bean

然后在配置文件中,如果要运行集成测试,则可以将值设置为false

async.enabled = false

,或者如果您使用的是Spring配置文件,则可以始终在其他配置文件配置文件(例如trueapplication.properties中将值设置为application-dev,并在{{ 1}}