Spring5中SpringWebContext方法過時的解決方案
Spring5 SpringWebContext方法過時
為了優(yōu)化訪問速度,應(yīng)對高并發(fā),想把頁面信息全部獲取出來存到redis緩存中,這樣每次訪問就不用客戶端進(jìn)行渲染了,速度能快不少。
thymeleafViewResolver.getTemplateEngine().process("goodslist.html",ctx);
里面的ctx參數(shù),這個參數(shù)就是WebContext
然后定義這個變量
SpringWebContext ctx = new SpringWebContext()
但是發(fā)現(xiàn)無法調(diào)用到,因為項目使用的是thymeleaf.spring5的版本
org.thymeleaf.spring4下面沒有相同類型的,
因為在thymeleaf.spring5的API中把大部分的功能移到了IWebContext下面,用來區(qū)分邊界。剔除了ApplicationContext 過多的依賴,現(xiàn)在thymeleaf渲染不再過多依賴spring容器
調(diào)用這個即可
IWebContext ctx =new WebContext(request,response, ? ? ? ? ? ? ? ? request.getServletContext(),request.getLocale(),model.asMap());
SpringWebContext在Spring5中報錯
想把頁面信息全部獲取出來存到redis緩存中,用
? ? ? ?SpringWebContext ctx = new SpringWebContext(request, response, ? ? ? ? ? ? ? ? request.getServletContext(), request.getLocale(), model.asMap(), applicationContext);
代碼報錯,
解決辦法(SpringWebContext在spring5中過時)
? //手動渲染 ? ? ? ? IWebContext ctx =new WebContext(request,response, ? ? ? ? ? ? ? ? request.getServletContext(),request.getLocale(),model.asMap());
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
SpringBoot+Quartz實現(xiàn)動態(tài)定時任務(wù)
這篇文章主要為大家詳細(xì)介紹了springBoot+Quartz實現(xiàn)動態(tài)定時任務(wù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-09-09springboot集成spark并使用spark-sql的示例詳解
這篇文章主要介紹了spring-boot集成spark并使用spark-sql的方法,本文通過示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-02-02SpringBoot整合screw實現(xiàn)自動生成數(shù)據(jù)庫設(shè)計文檔
使用navicat工作的話,導(dǎo)出的格式是excel不符合格式,還得自己整理。所以本文將用screw工具包,整合到springboot的項目中便可以自動生成數(shù)據(jù)庫設(shè)計文檔,非常方便,下面就分享一下教程2022-11-11Spring中@Import的各種用法以及ImportAware接口詳解
這篇文章主要介紹了Spring中@Import的各種用法以及ImportAware接口詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10