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

  • 相关阅读:
    转 无障碍阅读 role aria-*
    (转)edm注意事项
    Spring IOC机制之使用注解配置bean
    Spring IOC机制使用SpEL
    使用Spring IOC容器引用外部属性文件
    如何将属性文件中的值保存到类中
    基于XML的类的属性的装配
    Java——事务
    Eclipse中使用Spring IOC容器的具体方法
    Java之批处理的实现
  • 原文地址:https://www.cnblogs.com/happpytoo/p/10054011.html
Copyright © 2011-2022 走看看