信息发布→ 登录 注册 退出

Spring5中SpringWebContext方法过时的解决方案

发布时间:2026-01-11

点击量:
目录
  • Spring5 SpringWebContext方法过时
    • 调用这个即可
  • SpringWebContext在Spring5中报错
    • 解决办法(SpringWebContext在spring5中过时)

Spring5 SpringWebContext方法过时

为了优化访问速度,应对高并发,想把页面信息全部获取出来存到redis缓存中,这样每次访问就不用客户端进行渲染了,速度能快不少。

thymeleafViewResolver.getTemplateEngine().process("goodslist.html",ctx);

里面的ctx参数,这个参数就是WebContext

然后定义这个变量

SpringWebContext ctx = new SpringWebContext()

但是发现无法调用到,因为项目使用的是thymeleaf.spring5的版本

org.thymeleaf.spring4下面没有相同类型的,

因为在thymeleaf.spring5的API中把大部分的功能移到了IWebContext下面,用来区分边界。剔除了ApplicationContext 过多的依赖,现在thymeleaf渲染不再过多依赖spring容器

调用这个即可

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());

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!