为了应对在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

SpringBoot 2.0中SpringWebContext 找不到无法使用的问题解决的更多相关文章

  1. SpringBoot 2.0 中 HikariCP 数据库连接池原理解析

    作为后台服务开发,在日常工作中我们天天都在跟数据库打交道,一直在进行各种CRUD操作,都会使用到数据库连接池.按照发展历程,业界知名的数据库连接池有以下几种:c3p0.DBCP.Tomcat JDBC ...

  2. matlab运行过程中出现找不到指定模块问题解决

    对于matlab08版本以前的解决方法: 修改改环境变量: 新建变量名:BLAS_VERSION 变量值:D:\matlab7\bin\win32\atlas_Athlon.dll 在你的安装文件夹里 ...

  3. 【转】SpringBoot 2.0.0新版和SpringBoot1.5.2版本中Tomcat配置的差别

    https://blog.csdn.net/wd2014610/article/details/79587161 2018年春SpringBoot 2.0.0 新版本有了很多新的改变,其中Tomcat ...

  4. springboot 2.0 Redis command timed out的解决

    环境:springboot 2.0.7 spring data redis springboot从1.x升级到2.x后,spring data redis使用的redis客户端驱动从1.x的jedis ...

  5. SpringBoot从0到0.7——第四天

    SpringBoot从0到0.7--第四天 今天进行实战开发一个小项目,SpringBoot和Thymeleaf集成的小项目 因为懒得写写前端,直接找的别人的项目在它的的基础上进行配置,进行修改.gi ...

  6. FineUI(开源版)v6.0中FState服务器端验证的实现原理

    前言 1. FineUI(开源版)是完整开源,最早发起于 2008-04,下载全部源代码:http://fineui.codeplex.com/ 2. 你可以通过捐赠作者来支持FineUI(开源版)的 ...

  7. 在 Typescript 2.0 中使用 @types 类型定义

    在 Typescript 2.0 中使用 @type 类型定义 基于 Typescript 开发的时候,很麻烦的一个问题就是类型定义.导致在编译的时候,经常会看到一连串的找不到类型的提示.解决的方式经 ...

  8. Servlet3.0中Servlet的使用

    目录 1.注解配置 2.异步调用 3.文件上传 相对于之前的版本,Servlet3.0中的Servlet有以下改进: l  支持注解配置. l  支持异步调用. l  直接有对文件上传的支持. 在这篇 ...

  9. asp.net identity 2.2.0 中角色启用和基本使用(七)提示点

    在使用asp.net identity 2.2.0 中,大家可能设计到一些修改和配置 关于Identity的配置,在App_Start文件中的IdentityConfig.cs中,这里几乎有你需要的一 ...

随机推荐

  1. BZOJ_5338_ [TJOI2018]xor_可持久化trie

    BZOJ_5338_ [TJOI2018]xor_可持久化trie Description 有一棵点数为N的树,树边有边权.给你一个在0~N之内的正整数K,你要在这棵树中选择K个点,将其染成黑色,并 ...

  2. 【Lintcode】038.Search a 2D Matrix II

    题目: Write an efficient algorithm that searches for a value in an m x n matrix, return the occurrence ...

  3. 使用webdriver出现的问题:[18796:1808:0730/131103.313:ERROR:install_util.cc(600)] Failed to read HKLM\SOFTWARE\Policies\Google\Chrome\MachineLevelUserCloudPolicyEnrollmentToken: 系统找不到指定的文件。 (0x2) DevTools lis

    1.注册表导致 [5956:4996:0710/155156.898:ERROR:install_util.cc(589)] Unable to create registry key HKLM\SO ...

  4. Grunt:GruntFile.js

    ylbtech-Grunt:GruntFile.js 1.返回顶部 1. module.exports = function (grunt) { grunt.initConfig({ useminPr ...

  5. windows平台下新网络库RIO ( Winsock high-speed networking Registered I/O)

    What's New for Windows Sockets Microsoft Windows 8 and Windows Server 2012 introduce new Windows Soc ...

  6. python2和python3中的range区别

    python2中的range返回的是一个列表 python3中的range返回的是一个迭代值 for i in range(1,10)在python2和python3中都可以使用,但是要生成1-10的 ...

  7. SELinux处理命令

    1 查看SELinux状态 Enforcing为开启状态:Disabled为关闭状态. [root@localhost /]# getenforce Enforcing 2 临时关闭SELinux [ ...

  8. oracle 内连接 外连接 查询 笔记

    elect ename,job,sal from emp where deptno>10 order by sal desc; 联合查询,PK dept.deptno FK emp.deptno ...

  9. 多进程小例子--fork+pipe

    1 #include<stdio.h>  2 #include<unistd.h>  3   4 #define m 6  5 int main()  6 {  7       ...

  10. IOC模式及Unity框架文章收藏

    1.IoC模式:http://www.cnblogs.com/qqlin/archive/2012/10/09/2707075.html 通过Unity实现IOC容器. 2.深入理解DIP.IoC.D ...