gpt4 book ai didi

java - 如何在Spring WebFlux中设置ViewResolver

转载 作者:行者123 更新时间:2023-11-30 06:27:39 26 4
gpt4 key购买 nike

我的 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();
}

此后我的 View 解析器遇到了麻烦。它找不到我的任何观点。经过调查后,我意识到调试器不会在 ThymeleafReactiveViewResolver 类中停止。

此更改是否也可能更改了默认 View 解析器?我怎样才能把它带回来?

最佳答案

提供 httpHandler 会禁用 Spring Boot 的大量支持。

您可以将自己的 WebExceptionHandler 声明为一个组件(甚至是有序组件),Spring WebFlux 将为您选择它。如果没有更具体的示例(或者至少是您看到的堆栈跟踪/错误),很难理解发生了什么。

Spring Boot 现在支持 WebFlux 应用程序中的错误处理(请参阅 #8625 ),以防它实现您想要实现的目标。

关于java - 如何在Spring WebFlux中设置ViewResolver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46799457/

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