Bird
0
0

Which of the following is the correct way to declare an event listener method in Spring Boot?

easy📝 Syntax Q3 of 15
Spring Boot - Messaging
Which of the following is the correct way to declare an event listener method in Spring Boot?
A@EventListener public void handleEvent(MyEvent event) {}
B@Event public void handleEvent(MyEvent event) {}
C@Listener public void handleEvent(MyEvent event) {}
D@Subscribe public void handleEvent(MyEvent event) {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct annotation for event listeners

    Spring Boot uses @EventListener to mark methods that handle events.
  2. Step 2: Verify method signature and annotation

    The method must be public and accept the event object as parameter.
  3. Final Answer:

    @EventListener public void handleEvent(MyEvent event) {} -> Option A
  4. Quick Check:

    Event listener annotation = @EventListener [OK]
Quick Trick: Use @EventListener to mark event handler methods [OK]
Common Mistakes:
  • Using incorrect annotations like @Event or @Listener
  • Missing public access modifier
  • Wrong method parameter types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes