I am trying to implement my custom GlobalExceptionHandler class by extending AbstractErrorWebExceptionHandler (default implementation is DefaultErrorWebExceptionHandler class) but unable to do so as bean(stated below) is missing which is required in constructer initilization .I am not sure why this is happening as by default implemetation it is working fine and by giving my own implementation it is asking for a bean, Please help
@Component
@Order(-2)
public class GlobalExceptionHandler extends AbstractErrorWebExceptionHandler{
public GlobalExceptionHandler(ErrorAttributes errorAttributes, Resources resources, ApplicationContext applicationContext) {
super(errorAttributes, resources, applicationContext);
}
@Override
protected RouterFunction<ServerResponse> getRoutingFunction(ErrorAttributes errorAttributes) {
return RouterFunctions.route(RequestPredicates.all(),this::formatErrorResponse);
}
private Mono<ServerResponse> formatErrorResponse(ServerRequest request){
Map<String, Object> errorAttributesMap = getErrorAttributes(request, ErrorAttributeOptions.defaults());
int status = (int) Optional.ofNullable(errorAttributesMap.get("status")).orElse(500);
return ServerResponse
.status(status)
.contentType(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromValue(errorAttributesMap));
}
}
And error i am getting is:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 1 of constructor in com.example.userManagementSystem.demoApp.exception.GlobalExceptionHandler required a bean of type 'org.springframework.boot.autoconfigure.web.WebProperties$Resources' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.boot.autoconfigure.web.WebProperties$Resources' in your configuration.
Process finished with exit code 1
I am not sure why this is coming. PLease help!