I am trying to create my own ErrorWebExceptionHandler
in Spring Boot 2 by extending the default one but my application fails to start with the following message:
I just did this as well, and after looking at springs implementation I just added the components to the constructor.
@Component
@Order(-2)
class GlobalErrorWebExceptionHandler(
errorAttributes: ErrorAttributes,
resourceProperties: ResourceProperties,
applicationContext: ApplicationContext,
viewResolvers: ObjectProvider,
serverCodecConfigurer: ServerCodecConfigurer
) : AbstractErrorWebExceptionHandler(
errorAttributes,
resourceProperties,
applicationContext
) {
private val logger = LogFactory.getLog(GlobalErrorWebExceptionHandler::class.java)!!
init {
setViewResolvers(viewResolvers.orderedStream().collect(Collectors.toList()))
setMessageWriters(serverCodecConfigurer.writers)
setMessageReaders(serverCodecConfigurer.readers)
}
override fun getRoutingFunction(errorAttributes: ErrorAttributes) = RouterFunctions.route(RequestPredicates.all(), HandlerFunction { request ->
val ex = getError(request)
logger.error(ex.message)
ServerResponse.ok().build()
})
}