Bird
0
0

Identify the error in this Spring Boot configuration:

medium📝 Debug Q6 of 15
Spring Boot - Caching
Identify the error in this Spring Boot configuration:
@Configuration
public class CacheConfig {
  @Cacheable
  public String getData() { return "data"; }
}
ANo error; code is correct
B@Cacheable cannot be used on configuration classes
CMethod getData must be static
DMissing @EnableCaching annotation on configuration class
Step-by-Step Solution
Solution:
  1. Step 1: Check for @EnableCaching

    To enable caching, @EnableCaching must be present on a configuration or main class.
  2. Step 2: Analyze given code

    Code lacks @EnableCaching, so @Cacheable will not work properly.
  3. Final Answer:

    Missing @EnableCaching annotation on configuration class -> Option D
  4. Quick Check:

    Missing @EnableCaching disables caching [OK]
Quick Trick: Add @EnableCaching on config class to fix caching [OK]
Common Mistakes:
  • Thinking @Cacheable alone enables caching
  • Believing method must be static
  • Assuming no error in missing @EnableCaching

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes