gpt4 book ai didi

spring-boot - 创建自定义 ErrorWebExceptionHandler 失败

转载 作者:行者123 更新时间:2023-12-04 10:14:10 28 4
gpt4 key购买 nike

我正在尝试创建自己的 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com