I am new to spring boot and i have been trying to get a simple api request via postman. But, I am stuck with an error 404. Can someone point the errors in my code?.
I have a spring boot simple app build with maven and run in embedded tomcat through STS. I tried to send this request
http://localhost:8080/api/vi/menu/getAll
Here is my controller code:
@RestController
@RequestMapping("/api/v1/menu")
public class MenuController {
@Autowired
private MenuRepository menuRepository;
@GetMapping
@RequestMapping("/getAll")
public List<Menu> list() {
return menuRepository.findAll();
}
}
MenuRepository:
public interface MenuRepository extends JpaRepository<Menu, Integer> {}
The error status in postman:
{ "timestamp": "2022-08-05T04:46:28.489 00:00", "status": 404, "error": "Not Found", "path": "/api/vi/menu/getAll" }
The port is in default 8080.
I tried adding url to the getmapping after referring some online documentations, but still the error 404 is not resolved. Can someone point the error and explain me ?
Thanks.
CodePudding user response:
You are calling wrong URL
/api/vi/menu/getAll
correct url is
/api/v1/menu/getAll
Change vi to v1