Bird
0
0

Why is it important to place @EnableCaching on a configuration class rather than on a regular service class?

hard📝 Conceptual Q10 of 15
Spring Boot - Caching
Why is it important to place @EnableCaching on a configuration class rather than on a regular service class?
ABecause service classes cannot have annotations
BBecause @EnableCaching triggers global cache setup and should be on a config class
CBecause @EnableCaching only works on classes with main method
DBecause placing it on service classes disables caching
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of @EnableCaching

    @EnableCaching activates Spring's caching infrastructure globally.
  2. Step 2: Why on configuration class?

    It should be on a configuration or main class to apply caching support application-wide, not on individual beans.
  3. Final Answer:

    Because @EnableCaching triggers global cache setup and should be on a config class -> Option B
  4. Quick Check:

    @EnableCaching = global cache setup on config [OK]
Quick Trick: Put @EnableCaching on config class for global effect [OK]
Common Mistakes:
  • Thinking service classes cannot have annotations
  • Believing @EnableCaching works only on main classes
  • Assuming it disables caching on service classes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes