1

I'm writing tests for my Async method, annotated with @Async. I'm trying to disable Async by using below configuration class:

@Profile("!integ-test")
@Configuration
@EnableAsync
public class AsyncConfiguration {}

Calling code:

@Autowired private ApiDelegate apiDelegate;

apiDelegate.exportResources(searchContext);

Method:

 @Async
 public void exportResources(
  SearchContext searchContext,
  ) {}

Spring boot version: 2.3.12.RELEASE

The problem is the method is still being executed asynchronously. There is no place else where @EnableAsync is placed. I've also tried removing @EnableAsync altogether, but the method remains asynchronous. There seems to be no effect of removing @EnableAsync. Please help. Thanks.

9
  • 2
    Please show how you are executing the code as well as specifying which Spring Boot version you are using. Are you by any chance using spring-boot-starter-actuator as that will enable asyn and scheduling by default. Commented May 19, 2022 at 6:38
  • @M.Deinum Updated my question Commented May 19, 2022 at 6:45
  • Yes, I have org.springframework.boot:spring-boot-starter-actuator in dependencies. Commented May 19, 2022 at 6:46
  • Well if you have that async and scheduling is enabled by default as that is needed by actuator. Commented May 19, 2022 at 6:47
  • 1
    Thanks @M.Deinum. Is there any way I can override that behaviour? Commented May 19, 2022 at 6:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.