'org.springframework.boot.web.reactive.error.DefaultErrorAttributes is not getting called anymore in org.springframework.boot:2.3.1.RELEASE

Spring reactive web:

Earlier in spring boot 2.2.*, i was using a class that extends DefaultErrorAttributes. This class was used to handle exceptions globally for the overall micro service. When i upgrade to 2.3.1, it's not working anymore. I don't find any major change in spring reactive web in 2.3.1 version. Is there any change that breaks this? Anything we need to change? Any input?

it seems like DefaultErrorAttributes is not called anymore. Sample code is here.

@Slf4j
@Component
public class GlobalErrorAttributes extends DefaultErrorAttributes{`

@Override
public Map<String, Object> getErrorAttributes(ServerRequest request, 
  boolean includeStackTrace) {
    Map<String, Object> map = super.getErrorAttributes(
      request, includeStackTrace);
    map.put("status", HttpStatus.BAD_REQUEST);
    map.put("message", "username is required");
    return map;
}

}



Solution 1:[1]

I found Your answer and this works for me

@Component
@Slf4j
public class ErrorAttributes extends DefaultErrorAttributes
{
    @Override
    public Map<String, Object> getErrorAttributes(ServerRequest request, ErrorAttributeOptions options) {
        
        var attributes = new LinkedHashMap<String, Object>();
        attributes.put("status", HttpStatus.BAD_REQUEST.value());
        attributes.put("message", "bad");
        return attributes;
    }


}

I have Spring Boot in 2.3.1 version

Solution 2:[2]

I'm facing the same issue in Spring Boot 2.4.0. I solved it by following the workaround in this link https://github.com/spring-projects/spring-security/issues/4467. Adding:

.antMatchers("/error").permitAll()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gufi33
Solution 2 otidh