我的 Spring Boot Web Flux 应用程序已经有一段时间了。在这一点上,我想向我的路由器函数添加一些异常处理程序:
@Bean
RouterFunction<?> router(final GeneratorHandler generatorHandler) {
return resources("/**", new ClassPathResource("/static/"))
.andOther(route(GET("/generate"), generatorHandler::renderData)
.andRoute(GET("/index"), generatorHandler::renderIndex));
}
所以我添加了另一个这样的bean:
@Bean
HttpHandler httpHandler(final GeneratorHandler generatorHandler) throws Exception {
return WebHttpHandlerBuilder.webHandler(toHttpHandler(router(generatorHandler)))
.prependExceptionHandler((serverWebExchange, exception) -> {
//process here
return null;
})
.build();
}
在此之后,我的视图解析器出现了问题。它找不到我的任何观点。经过调查,我意识到调试器不会在 ThymeleafReactiveViewResolver 类中停止。
此更改是否也更改了默认视图解析器?我怎样才能把它带回来?
提供您httpHandler
禁用 Spring Boot 的大量支持。
你可以将你自己的WebExceptionHandler
,声明为一个组件(甚至是一个有序的),Spring WebFlux 会为你挑选它。没有更具体的例子(或者至少是你看到的堆栈跟踪/错误),很难理解发生了什么。
Spring Boot 现在支持 WebFlux 应用程序中的错误处理(请参阅#8625),以防它执行您想要实现的目标。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句