Spring Boot Rest API Returns 404

404-not-found-while-running-spring-boot-rest-api

I got the solution. It was due to package visibility.
Main class was not able to find package in which controller class is present.
So, I added all classes under the same package. You can also place application class one level up.

Got help from below link:

Spring Boot: Cannot access REST Controller on localhost (404)

How to return 404 response status in Spring Boot @ResponseBody - method return type is Response?

Create a NotFoundException class with an @ResponseStatus(HttpStatus.NOT_FOUND) annotation and throw it from your controller.

@ResponseStatus(code = HttpStatus.NOT_FOUND, reason = "video not found")
public class VideoNotFoundException extends RuntimeException {
}

Rest API response 404 Not found when run project with Java Application

When you run your project as jar (java application), you should use localhost:8080/demo/user

When you run your application into a server (jboss per example) the name of your war file is the root path.

localhost:8080/MySecret/demo/user

I think your war file is MySecret.war.

That's the reason of the difference between the first and the second. Since you don't have a base path, /demo/user is the path of your endpoint.

Spring boot gives 404 status although request comes into endpoint

I solved the issue. That is my mistake. I forgot to return ResponseEntity as the response. After returning ResponseEntity, the problem is solved...



Related Topics



Leave a reply



Submit