Hi,
I just tried to write a bean class(users) to return two string values using contructor.
But am getting the following error:
The application has no explicit mapping for /error, so you are seeing this as a fallback.
There was an unexpected error (type= not found, status =404)
No handler found for GET/users
Please help.
Instructor
Yogesh Chawla Replied on 14/09/2020
Hi Preethi,
There are multiple things here.
To catch hold of exceptions, remember in 4th Module, We wrote sth like this and returned "error" String back so as to show error jsp back on UI in case of invalid login.
@PostMapping("/login")
public String login(@ModelAttribute("login") Login login){
User user = userRepository.searchByName(login.getUsername());
if(user == null){
throw new ApplicationException("User Not Found");
}
System.out.println("In Login Controller Flow");
return "search";
}
@ExceptionHandler(ApplicationException.class)
public String handleException(){
System.out.println("iN exception handler of Login Controller");
return "error";
}
If you have this property set in application.properties
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration
This does not show default White Label Error Page as part of browser and and rather shows the HTTP error message which you have got.
In case you still could not able to handle the exception in your scenario, just Whatsapp us at +91-9878787630. We will look at your code and help you out.