1. 程式人生 > 實用技巧 >WebFlux中thymeleaf檢視找不到的問題解決

WebFlux中thymeleaf檢視找不到的問題解決

由於在weblux臨時增加一個H5的頁面,發生如下錯誤

Whitelabel Error Page

This application has no configured error view, so you are seeing this as a fallback.

Fri Nov 27 11:18:57 CST 2020 There was an unexpected error (type=Internal Server Error, status=500). Could not resolve view with name 'index'.

最開始以為是檢視路徑的問題,測試沒通過,考慮其它的解決方案,在網上找了一些,其實朋友說需要增加自定義模板配置,遂記錄之.

@Configuration
@EnableWebFlux
public class WebAppConfig implements WebFluxConfigurer {

    //引入spring-boot-starter-thymeleaf自動會注入該bean
    @Autowired
    private ThymeleafReactiveViewResolver thymeleafReactiveViewResolver;


    /**
     * 加入thymeleaf試圖解析器,不然找不到view name
     *
     * @param registry
     */
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.viewResolver(thymeleafReactiveViewResolver);
    }

}