为了应对在SpringBoot中的高并发及优化访问速度,咱们通常会把页面上的数据查询出来,而后放到redis中进行缓存。减小数据库的压力。html
在SpringBoot中通常使用前端
thymeleafViewResolver.getTemplateEngine().process("goodlist", ctx);git
进行页面的渲染,而这个ctx就是SpringWebContext对象,咱们通常进行以下获取:程序员
SpringWebContext swc=new SpringWebContext(request,response,request.getServletContext(),request.getLocale(),model.asMap(),applicationContext);github
在SpringBoot 1.X的版本中以上代码可使用。但在SpringBoot 2.0中,就没法找到SpringWebContext了。那应该如何去解决这个问题呢?redis
说一下个人思路,.process方法中ctx所在参数所须要的类型为接口IContext数据库
也就是须要有实现了IContext的类就能够了,而后进入IContext接口找全部的实现类后端
而后看到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、JSR30三、MyBatis
2.前端:Thymeleaf、BootStrap、Jquery
3.中间件:RabbitMQ、Redis、Druid