Bird
0
0

Which of the following is the correct way to publish a custom event using ApplicationEventPublisher?

easy📝 Conceptual Q2 of 15
Spring Boot - Advanced Patterns
Which of the following is the correct way to publish a custom event using ApplicationEventPublisher?
AapplicationEventPublisher.publishEvent(new CustomEvent(this));
BapplicationEventPublisher.sendEvent(new CustomEvent());
CapplicationEventPublisher.fireEvent(new CustomEvent(this));
DapplicationEventPublisher.triggerEvent(new CustomEvent());
Step-by-Step Solution
Solution:
  1. Step 1: Recall the method to publish events

    The correct method is publishEvent() which takes an event object as argument.
  2. Step 2: Check method signatures

    Only applicationEventPublisher.publishEvent(new CustomEvent(this)); uses publishEvent() with a proper event instance including the source.
  3. Final Answer:

    applicationEventPublisher.publishEvent(new CustomEvent(this)); -> Option A
  4. Quick Check:

    Publish event method = publishEvent() [OK]
Quick Trick: Use publishEvent() method to send events [OK]
Common Mistakes:
  • Using non-existent methods like sendEvent or fireEvent
  • Not passing the event source in constructor
  • Confusing method names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes