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)文章
Go Java算法之外觀數(shù)列實現(xiàn)方法示例詳解
這篇文章主要為大家介紹了Go Java算法外觀數(shù)列實現(xiàn)的方法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08
Spring中@PropertySource注解使用場景解析
這篇文章主要介紹了Spring中@PropertySource注解使用場景解析,@PropertySource注解就是Spring中提供的一個可以加載配置文件的注解,并且可以將配置文件中的內(nèi)容存放到Spring的環(huán)境變量中,需要的朋友可以參考下2023-11-11

