Skip to content
Advertisement

Why do I get 404 Not Found in Spring Boot

My Spring Boot application sends data through REST API. I connects to many Google Cloud components: google pubsub, mqtt server and google SQL. Since I implemented PUBSUB and MQTT, whenever I send a request from Postman I receive not found response

My pom.xml configuration looks like this

JavaScript

I also found that request is being served by backend to the point of return, so if backend throws an Exception during request processing, it returns 500 Internal Server error enter image description here

Even the record is being inserted to database

JavaScript

This is my controller

JavaScript

here’s stack trace when 500 is returned

JavaScript

and here is the code snippet of that service

JavaScript

I am not interested in the error, I know why it is being thrown. I want to figure out why response returns 404 when the endpoint exists.

Advertisement

Answer

Ok, so the issue was very silly, and the solution is super simple:

I was using @Controller adnotation in my RfidReaderController which is from springframework.stereotype library. I changed it to @RestController and now it works. just as follows:

JavaScript
Advertisement