0

I have written a simple code for springboot with rest controller. It runs fine but does not hit the endpoint.

My Application class:

@SpringBootApplication
public class SpringbootRestTemplateDemo {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootRestTemplateDemo.class, args);
        System.out.println("Springboot Rest template demo");
    }

}

My controller class:

@RestController
public class ProductController {

    @RequestMapping(value="/product/details", method=RequestMethod.GET)
    public String getProduct() {
        return "Product details";

    }
}

I expect a simple message using get request but it is not hitting the endpoint. Input: http://localhost:8080/product/details

output:

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.

Thu Mar 28 19:34:44 IST 2019 There was an unexpected error (type=Not Found, status=404). No message available

Abder KRIMA
  • 3,418
  • 5
  • 31
  • 54
Ruban
  • 1
  • 5

1 Answers1

0

We would likely need to see the folder structure to fully understand. My current guess is its possible that your main class is not in a root package above other classes.

When you run a Spring Boot Application, (i.e. a class annotated with @SpringBootApplication), Spring will only scan the classes below your main class package.

see previous answer: This application has no explicit mapping for /error

  • Thanks Shane, It was indeed the folder structure issue as you mentioned above. I changed it and works fine now. – Ruban Mar 29 '19 at 07:50