Bird
0
0

Consider this Spring Boot setup:

medium📝 Debug Q14 of 15
Spring Boot - Async Processing
Consider this Spring Boot setup:
@Configuration
public class AsyncConfig {
  @Async
  public void runAsync() {
    System.out.println("Running async");
  }
}

What is the main problem with this code?
AMissing <code>@EnableAsync</code> annotation to activate async support
BMethods annotated with <code>@Async</code> must return a value
C<code>@Async</code> cannot be used inside <code>@Configuration</code> classes
DThe method must be static to run asynchronously
Step-by-Step Solution
Solution:
  1. Step 1: Check if async support is enabled

    Without @EnableAsync on a configuration or main class, Spring will not run @Async methods asynchronously.
  2. Step 2: Validate other options

    @Async methods can be void, can be in any Spring bean, and do not need to be static.
  3. Final Answer:

    Missing @EnableAsync annotation to activate async support -> Option A
  4. Quick Check:

    Enable async missing = async won't run [OK]
Quick Trick: Always add @EnableAsync to activate async methods [OK]
Common Mistakes:
  • Thinking @Async needs return value
  • Believing @Async can't be in config classes
  • Assuming method must be static

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes