我正在尝试创建自己的 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]
我的处理程序(Kotlin 代码):
@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
}
}
可能是什么原因?
最佳答案
请尝试在您的构造函数中添加 ServerCodecConfigurer 的依赖项
GlobalErrorWebExceptionHandler(
ErrorAttributes errorAttributes,
ResourceProperties resourceProperties,
ApplicationContext applicationContext,
ServerCodecConfigurer configurer
) {
super(errorAttributes, resourceProperties, applicationContext);
this.setMessageWriters(configurer.getWriters());
}
关于spring-boot - 创建自定义 ErrorWebExceptionHandler 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52497901/