一尘不染

创建自定义ErrorWebExceptionHandler失败

spring-boot

我试图ErrorWebExceptionHandler通过扩展默认启动项在Spring Boot
2中创建自己的启动项,但是我的应用程序无法以以下消息启动:

Caused by: java.lang.IllegalArgumentException: Property 'messageWriters' is required
at org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler.afterPropertiesSet(AbstractErrorWebExceptionHandler.java:214) ~[spring-boot-autoconfigure-2.0.4.RELEASE.jar:2.0.4.RELEASE]

我的处理程序(科特琳代码):

@Component
@Order(-2)
class SampleErrorWebExceptionHandler(
    errorAttributes: ErrorAttributes?,
    resourceProperties: ResourceProperties?,
    errorProperties: ErrorProperties?,
    applicationContext: ApplicationContext?
) : DefaultErrorWebExceptionHandler(errorAttributes, resourceProperties, errorProperties, applicationContext) {

    override fun logError(request: ServerRequest, errorStatus: HttpStatus) {
        // do something
    }
}

可能是什么原因?


阅读 2363

收藏
2020-05-30

共1个答案

一尘不染

您需要messageWriters在该实例上设置on,因为这里需要它们。您可能应该将其创建为a @Bean,就像Spring
Boot在专用自动配置中所做的那样

2020-05-30