In my Springboot application even though the rest endpoint is being hit correctly as seen from log message I am getting the following 404 error.
I have a springboot application with the following main class:-
package com.springbootbasic; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class SpringbootBasicApplication { public static void main(String[] args) { SpringApplication.run(SpringbootBasicApplication.class, args); } } Following is the controller class:-
package com.springbootbasic; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class HomeController { Logger logger = LoggerFactory.getLogger(HomeController.class); @RequestMapping("/hello") public String home(Model model) { logger.info("Rest endpoint /hello is being hit correctly."); return "index.html"; } @RequestMapping("/home") @ResponseBody public String response() { logger.info("Rest endpoint /home is being hit correctly."); return "Very well done the rest end point is working fine."; } } The above two classes are in the same package and the HomeController is annotated with @Controller and not the @RestController.
And in the src/main/public source folder of eclipse I have created the following index.html file.
<!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Welcome from Home</title> </head> <body> <h2>Hello World!</h2> </body> </html> And in the browser when I am hitting the url http://localhost:8080/hello I am getting the following error :-
There was an unexpected error (type=Not Found, status=404). No message available But the log message is :-
2019-08-28 20:22:38.953 INFO 20864 --- [nio-8080-exec-1] c.springbootbasic.HomeController : Rest endpoint /hello is being hit correctly. 2019-08-28 20:22:52.179 INFO 20864 --- [nio-8080-exec-3] c.springbootbasic.HomeController : Rest endpoint /home is being hit correctly. 2019-08-28 20:25:20.858 INFO 20864 --- [nio-8080-exec-6] c.springbootbasic.HomeController : Rest endpoint /hello is being hit correctly. How to fix this?