Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.2K
Views
Missing Resources bean : Springboot web-flux Custom Global Exception handler

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!

over 4 years ago · Santiago Trujillo
4 answers
Answer question

0

@Slf4j
@Component
@Order(-99)
public class ExceptionHandler implements WebExceptionHandler {
    @Override
    public Mono<Void> handle(ServerWebExchange serverWebExchange, Throwable throwable) {
        ServerHttpResponse response = serverWebExchange.getResponse();
        response.setStatusCode(HttpStatus.BAD_REQUEST);
        response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
        JSONObject resMsg = new JSONObject();
        try {
            resMsg.put("code", HttpStatus.BAD_REQUEST.value());
            if(throwable instanceof CommonException){
                resMsg.put("msg", ((CommonException) throwable).getMsg());
            }else{
                log.error("system error:", throwable);
                resMsg.put("msg", CommonCode.PLATFORM_ERR_MSG);
            }
        } catch (Exception e) {
        }

        DataBuffer db = response.bufferFactory().wrap(resMsg.toString().getBytes(Charset.forName("UTF-8")));
        return response.writeWith(Mono.just(db));
    }
}
over 4 years ago · Santiago Trujillo Report

0

bro. Sorry for my English. Y can inject WebProperties. Next step y can do getResourses() from this properties. I hope that I help to you.

over 4 years ago · Santiago Trujillo Report

0

I was getting the same exception when I migrated my Webflux api application from Springboot version 2.5.x to 2.6.2.

To resolve it I added a configuration class which creates a Bean for WebProperties.Resources as below,

@Configuration
public class ResourceWebPropertiesConfig {

    @Bean
    public WebProperties.Resources resources() {
        return new WebProperties.Resources();
    }

}

This solved the issue. I guess something have changed in Springboot version 2.6.x

over 4 years ago · Santiago Trujillo Report

0

The root of the issue is that ResourceProperties (which is the one that was bound to spring.resources) was removed in Spring Boot 2.6 (had been deprecated since 2.4) as explained here and also in the said version release notes.

Injecting the WebProperties bean in your constructor and then calling WebProperties.getResources() at the usage point should fix your custom global exception handler as shown in the following snippet:

@Component
@Order(-2)
public class GlobalExceptionHandler extends AbstractErrorWebExceptionHandler{

    // Spring boot 2.5.x 
    public GlobalExceptionHandler(ErrorAttributes errorAttributes, Resources resources, ApplicationContext applicationContext) {
        super(errorAttributes, resources, applicationContext);
    }

    // Spring boot 2.6.0
    public GlobalExceptionHandler(ErrorAttributes errorAttributes, WebProperties webProperties, ApplicationContext applicationContext) {
        super(errorAttributes, webProperties.getResources(), applicationContext);
    }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!