Reputation: 450
I am trying to call spring-boot rest controller but it throws o.s.web.servlet.pagenotfound spring boot, I have seen too many answers here but none of these helped me.
controller class is as below
@RestController
@RequestMapping("/users")
public class UsersController {
@Autowired
private UsersRepository usersRepository;
@GetMapping("/users")
public List<Users> getAllUsers() {
return usersRepository.findAll();
}
}
And application.yml is as below
spring.datasource.url = jdbc:mysql://localhost:3306/mydb?useSSL=false
spring.datasource.username=mine
spring.datasource.password=mine
kindly let me know if any further information required
Upvotes: 2
Views: 573
Reputation: 384
I had the same problem, there should be a problem with your URL. You must be hitting the wrong URL.
I'm assuming you are using Postman for testing the GET Request.
Check if you are hitting through GET Request, and the format is JSON.
And try the below:
@RestController
@RequestMapping(value = "/")
public class UsersController {
@Autowired
private UsersRepository usersRepository;
@GetMapping("/users")
public List<Users> getAllUsers() {
return usersRepository.findAll();
}
}
Upvotes: 2