Bird
0
0

Identify the error in the following Spring Boot configuration that prevents caching from working:

medium📝 Debug Q14 of 15
Spring Boot - Caching
Identify the error in the following Spring Boot configuration that prevents caching from working:
@Configuration
public class CacheConfig {
  @Bean
  public CacheManager cacheManager() {
    return new ConcurrentMapCacheManager("items");
  }
}
ACache name "items" is invalid
BMissing <code>@EnableCaching</code> annotation on configuration class
CCacheManager bean should return null
DCacheManager must be annotated with <code>@Service</code>
Step-by-Step Solution
Solution:
  1. Step 1: Check caching activation

    Defining a CacheManager bean is not enough; caching must be enabled with @EnableCaching.
  2. Step 2: Verify other options

    CacheManager returning null or invalid cache names are incorrect; @Service is unrelated here.
  3. Final Answer:

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

    Enable caching with @EnableCaching [OK]
Quick Trick: Always add @EnableCaching to activate caching [OK]
Common Mistakes:
  • Forgetting to add @EnableCaching annotation
  • Misunderstanding CacheManager bean role
  • Wrong annotation usage on CacheManager

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes