๐ด The Error You're Seeing
Confirm this matches your console output. If it does, you're in the right place.
2026-03-01 11:45:05.200 WARN 8842 --- [nio-8080-exec-4] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.bind.MissingServletRequestParameterException: Required request parameter 'email' for method parameter type String is not present]โก Quick Fix Works 80% of the time
Add required = false to the @RequestParam annotation, or provide a defaultValue.
@GetMapping
public String getUser(@RequestParam(required = false) String email) { ... }๐ง Why this Happens
Tap to expand the deep technical explanation
Your controller method is annotated with @RequestParam for a parameter that is marked as required (the default). When the HTTP request arrived, Spring could not find that specific query string parameter in the URL, so it rejected the request with a 400 status code.
The HITEC City Parking Spot Analogy:
It is like a bouncer at a club requiring an ID. If you walk up and say 'I want to enter', but don't hand over your ID, the bouncer refuses to let you in.
๐ How to Reproduce Confirm this is your error
Call a GET endpoint whose @RequestParam parameter is required but omit the query parameter in the URL. Spring returns 400 Required request parameter 'X' is not present.
๐ ๏ธ Solutions (3 Ways to Fix)
Make the parameter optional
๐ Use this if the query parameter is not strictly mandatory.
Setting required = false tells Spring that if the parameter is missing, it should pass null to the method instead of throwing an exception.
@GetMapping("/search")
public String search(@RequestParam(required = false) String email) {
if (email == null) {
return "No email provided";
}
return "Searching for " + email;
}Provide a default value
๐ Use this if you want a fallback value when the parameter is missing.
If the client doesn't send the parameter, Spring will inject the defaultValue string instead.
@GetMapping("/users")
public List<User> getUsers(@RequestParam(defaultValue = "1") int page) {
// If ?page= is missing, page defaults to 1
return userService.getUsers(page);
}Ensure the client sends the parameter
๐ Use this if the parameter is mandatory and the client is buggy.
If the parameter is required (the default), ensure your frontend or API client is actually appending it to the URL.
// Frontend must send:
// http://localhost:8080/api/search?email=deva@test.com
// Backend:
@GetMapping("/search")
public String search(@RequestParam String email) { // required = true by default
return email;
}๐ Version Notes
Returns 400 Bad Request.
Returns 400 Bad Request, RFC 7807 ProblemDetail format.
๐ก๏ธ How to Prevent This Next Time
Use @RequestParam(required = false) or defaultValue for optional filters. For mandatory parameters, ensure your API documentation clearly states they are required.