Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in spring-boot appplication : This application has no explicit mapping for /error, so you are seeing this as a fallback

I have created a simple spring boot application in Eclipse which has User class and I have written web services to perform various operations on User such as get-users, create-user, delete-user.

When I am testing the application from the browser, I am getting the below error: This application has no explicit mapping for /error, so you are seeing this as a fallback.

The path that I used: http://localhost:8080/user/get-user/Mike I have annotated User resource class @RestController and Application class @SpringBootApplication.

Code snippet :

@RequestMapping(method = RequestMethod.GET, path = "/user/get-user/{name}" )
public User getUserByName(@PathVariable String name) {
    
    System.out.println("Request for name: "+name);
    return service.getUser(name); // this return the first user found with given name
}

Here is my project structure: Project Structure

like image 371
borkarda Avatar asked Oct 20 '25 16:10

borkarda


2 Answers

Just had a look at your project structure. In your case, you need to ensure that your main class is in a root package above other classes.

Whenever a Spring Boot Application is started or run (example : Application.java or a class annotated with @SpringBootApplication), it scans the classes below your main class package.

An example would be :

com
   +- test
         +- Application.java 
         |
         +- controller
         |   +- UserRestController.java
         +- domains
             +- User.java

Try this and check. Also, please ensure that you have added all the necessary annotations required on all the required classes for a Spring boot application for work correctly.

like image 82
Anirudh Avatar answered Oct 23 '25 06:10

Anirudh


In my case (I ended up here, looking for a solution, Stackoverflow is great!), I had forgotten to add the thymeleaf dependency.

like image 37
HellishHeat Avatar answered Oct 23 '25 07:10

HellishHeat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!