我试图ErrorWebExceptionHandler通过扩展默认启动项在Spring Boot 2中创建自己的启动项,但是我的应用程序无法以以下消息启动:
ErrorWebExceptionHandler
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 } }
可能是什么原因?
您需要messageWriters在该实例上设置on,因为这里需要它们。您可能应该将其创建为a @Bean,就像Spring Boot在专用自动配置中所做的那样。
messageWriters
@Bean