Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring boot controllers not getting registered; getting 404

I am running spring-boot application in intellij and all of my scheduled tasks and everything is working fine but my controller which i have registered with @RestController and @RequestMapping are not getting registered. I am getting 404 when trying to access these while same is working fine when i am using eclipse. Even my ide console is showing rest controller as registered:

RequestMappingHandlerMapping  - Mapped "{[/api/{v1}/restaurant/{cloudSiteId}/staff/{staffId}],methods=[GET]}" onto private java.lang.Object com.limetray.inventory.controller.StaffLocationController.getStaffDetail

Not able to guess what might go wrong ?

like image 345
Rakesh Yadav Avatar asked Jun 17 '16 10:06

Rakesh Yadav


People also ask

Why does Spring boot say 404 error?

We went through the two most common reasons for receiving a 404 response from our Spring application. The first was using an incorrect URI while making the request. The second was mapping the DispatcherServlet to the wrong url-pattern in web. xml.

What causes NoHandlerFoundException?

Class NoHandlerFoundException By default when the DispatcherServlet can't find a handler for a request it sends a 404 response. However if its property "throwExceptionIfNoHandlerFound" is set to true this exception is raised and may be handled with a configured HandlerExceptionResolver.

How do I stop WhiteLabel error page?

Another way of disabling the WhiteLabel Error is excluding the ErrorMvcAutoConfiguration . Alternatively, the exclusion can be done in an annotation. When the WhiteLabel Error Page is disabled and no custom error page is provided, the web server's error page (Tomcat, Jetty) is shown.


1 Answers

If your controller is in a separate package from your Main class you can try adding a component scan to your main class pointing to the package you have your controllers in. Example:

@ComponentScan({ "x.y.z.myPackage1", "x.y.z.myPackage2" })
like image 92
Matthew Fontana Avatar answered Sep 27 '22 22:09

Matthew Fontana