Problem Description
The error originates during request processing in a Spring Boot aplpication:
org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'timestamp' cannot be found on object of type 'java.util.HashMap' - maybe not public?
This happens when Spring attempts to evaluate expressions in error handling mechanisms, particularly within the ErrorMvcAutoConfiguration component where it tries to resolve placeholders in error views.
Error Enalysis
The issue manifests specifically when using a Node.js client (via needle library) to make GET requests to endpoints that expect POST requests. The same request works fine through Postman, suggesting the problem lies in how headers or parameters are being sent.
Key findings from investigation:
- Filter component was disabled but error persisted
- Error occurs during view resolution in error handling flow
- Error handling mechanism expects certain model attributes like 'timestamp', 'status', etc.
- Mismatch between HTTP method used in client (GET) vs server endpoint (POST)
Solution Approach
After systematic debugging, two key fixes were identified:
- Correct HTTP Method Usage: Ensure client makes POST requests to POST endpoints
- Proper Error Hendling Configuration: Add missing attributes to error model objects
The core fix involved modifying the global exception handler to populate required model attributes:
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
public ResponseEntity<Map<String, Object>> handleException(Exception e) {
Map<String, Object> errorResponse = new HashMap<>();
errorResponse.put("timestamp", System.currentTimeMillis());
errorResponse.put("error", "No error page");
errorResponse.put("status", 200);
errorResponse.put("message", e.getMessage());
return ResponseEntity.status(500).body(errorResponse);
}
}
Additionally, applying @RestControllerAdvice annotation ensures all exceptions return JSON responses automatically without requiring @ResponseBody annotations on individual methods.