๐Ÿ”ด The Error You're Seeing

Confirm this matches your console output. If it does, you're in the right place.

ERROR LOG2026-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)

Solution 1โœ“ Most common cause

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; }
Solution 2

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); }
Solution 3

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

Spring Boot 2.x

Returns 400 Bad Request.

Spring Boot 3.x

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.

Course Search
Search across all chapters & stages
๐Ÿ“–

Search the course

Type any topic โ€” branching, stash, rebase, hooks โ€” and jump straight to that chapter.

merge branchesgit stashundo commitrebase