Bird
0
0

Why does this cache key cause a runtime error? @Cacheable(value = "data", key = "#param.length()") when the method parameter is an Integer named 'param'.

medium📝 Debug Q7 of 15
Spring Boot - Caching
Why does this cache key cause a runtime error? @Cacheable(value = "data", key = "#param.length()") when the method parameter is an Integer named 'param'.
AInteger has no length() method, causing a method not found error
BThe key expression syntax is invalid
CThe cache name 'data' is reserved
DThe parameter name 'param' is not recognized
Step-by-Step Solution
Solution:
  1. Step 1: Check method call on parameter type

    Integer type does not have a length() method, so calling it causes an error.
  2. Step 2: Confirm error cause

    This leads to a runtime method not found exception during cache key evaluation.
  3. Final Answer:

    Integer has no length() method, causing a method not found error -> Option A
  4. Quick Check:

    Use valid methods for parameter types in SpEL keys [OK]
Quick Trick: Check parameter types before calling methods in cache keys [OK]
Common Mistakes:
  • Assuming syntax error instead of runtime error
  • Thinking cache name causes error
  • Ignoring parameter name correctness

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes