zoukankan      html  css  js  c++  java
  • SpringBoot 2.0中SpringWebContext 找不到无法使用的问题解决

    为了应对在SpringBoot中的高并发及优化访问速度,我们一般会把页面上的数据查询出来,然后放到redis中进行缓存。减少数据库的压力。

    SpringBoot中一般使用

    thymeleafViewResolver.getTemplateEngine().process("goodlist", ctx);

    进行页面的渲染,而这个ctx就是SpringWebContext对象,我们一般进行如下获取:

    SpringWebContext swc=new SpringWebContext(request,response,request.getServletContext(),request.getLocale(),model.asMap(),applicationContext);

    在SpringBoot 1.X的版本中以上代码可以使用。但在SpringBoot 2.0中,就无法找到SpringWebContext了。那应该如何去解决这个问题呢?

    说一下我的思路,.process方法中ctx所在参数所需要的类型为接口IContext

     
    image

    也就是需要有实现了IContext的类就可以了,然后进入IContext接口找所有的实现类

     
    image

    然后看到WebContext似乎有些像上面所用的SpringWebContext。即做出如下改变,完美实现了thymeleaf的页面渲染。

    WebContext ctx = new WebContext(request, response, request.getServletContext(), request.getLocale(), model.asMap());
    html = thymeleafViewResolver.getTemplateEngine().process("goodlist", ctx);

    在SpringBoot 2.0中使用上述代码,可以完全替代。

    (当然在下不才,暂时只找到了这种办法,在网络上也没找到对应的比较不错的策略。所以分享出来,以备分享出来,帮助遇到此问题的程序员们。如果大家有什么更好的处理办法可以一起互相交流哦)

    目前我正在搞基于SpringBoot、Redis、消息队列的秒杀小项目,主要还是为了梳理如何解决高并发的问题过程。

    GitHub:https://github.com/iquanzhan/SecKillShop

    欢迎点击Start哦

    所用技术

    1.后端:SpringBoot、JSR303、MyBatis

    2.前端:Thymeleaf、BootStrap、Jquery

    3.中间件:RabbitMQ、Redis、Druid

  • 相关阅读:
    常用加密算法的Java实现总结(二) ——对称加密算法DES、3DES和AES
    常用加密算法的Java实现(一) ——单向加密算法MD5和SHA
    在服务器上用Fiddler抓取HTTPS流量
    org.apache.commons.lang下的工具类
    Spring-bean作用域scope详解
    Tomcat性能调优方案
    JavaScript 闭包究竟是什么
    JavaScript跨域总结与解决办法
    《JAVA与模式》之简单工厂模式
    hibernate缓存机制详细分析
  • 原文地址:https://www.cnblogs.com/happpytoo/p/10054011.html
Copyright © 2011-2022 走看看