๐Ÿ”ด The Error You're Seeing

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

ERROR LOGWhitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Wed Oct 25 10:15:30 IST 2023 There was an unexpected error (type=Not Found, status=404). No message available

โšก Quick Fix Works 80% of the time

Ensure your controller class is annotated with @RestController and the method matches the exact HTTP path.

@RestController @RequestMapping("/api") public class MyController { @GetMapping("/hello") public String hello() { return "Hello"; } }

๐Ÿ› ๏ธ Solutions (3 Ways to Fix)

Solution 1โœ“ Most common cause

Verify @RestController annotation

๐Ÿ‘‰ Use this if you wrote a controller method but forgot to annotate the class.

If you use @Controller instead of @RestController, Spring tries to find an HTML view instead of returning JSON, leading to 404s.

@RestController public class MyController { ... }
Solution 2

Check URL path matching

๐Ÿ‘‰ Use this if your annotations are correct but the URL is wrong.

Ensure the URL you are hitting exactly matches the @RequestMapping and @GetMapping paths, including slashes.

// Controller: @GetMapping("/api/users") // Correct URL: http://localhost:8080/api/users // Wrong URL: http://localhost:8080/users
Solution 3

Fix Component Scan for Controllers

๐Ÿ‘‰ Use this if your controller is in a different package than your main Application class.

Spring Boot only scans the package of the main class and its sub-packages. If your controller is in a sibling package, it won't be registered.

@SpringBootApplication @ComponentScan(basePackages = {"com.devinhyderabad.controllers", "com.devinhyderabad.services"})

๐Ÿ“‹ Version Notes

Spring Boot 2.x

Throws NoHandlerFoundException if spring.mvc.throw-exception-if-no-handler-found is true.

Spring Boot 3.x

Throws NoHandlerFoundException by default without needing the property.

๐Ÿง  Why this Happens

Tap to expand the deep technical explanation

Spring Boot's embedded Tomcat server received an HTTP request, but could not find any Java method mapped to that specific URL path. This usually means the controller is missing, the URL is typed wrong, or the controller isn't being scanned by Spring.

The HITEC City Parking Spot Analogy:

It's like dialing a phone number that isn't connected to anyone. The network works, but there's no one at that specific extension to answer.

๐Ÿ›ก๏ธ How to Prevent This Next Time

Always test API endpoints using Postman or curl immediately after creating them to verify the mapping.

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