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
也就是需要有实现了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、JSR303、MyBatis
2.前端:Thymeleaf、BootStrap、Jquery
3.中间件:RabbitMQ、Redis、Druid
- Spring Boot2.0中SpringWebContext找不到无法使用的解决方法
- 解决spring-boot2.0.6中webflux无法获得请求IP的问题
- IntelliJ IDEA中Spring Boot项目使用spring-boot-devtools无法实现热部署/热更新的问题解决
- 多种方式解决spring boot swagger ui使用 nginx 部署后无法使用问题
- @maohoo Spring boot 配置Tomcat 根目录,解决web资源目录找不到的问题
- 解决spring boot swagger ui使用 nginx 部署后无法使用问题
- 找不到org.springframework.web.context.ContextLoaderListener问题解决
- 解决Spring boot中使用Gson,Swagger2 api-docs无法正常显示json问题
- 解决Spring boot使用Quartz时Job中无法注入Bean 空指针异常问题
- 解决spring boot websocket无法注入bean的问题
- 解决spring boot websocket无法注入bean的问题
- maven创建web工程Spring配置文件找不到问题解决方案
- 解决myeclipse中新建javaweb工程,无法使用Web App Libraries问题
- Win7系统解决使用MyEclipse进行Web开发中网页无法显示.woff矢量图标的问题
- 解决springboot项目打war 包docker包找不到resource 下的静态资源问题
- 解决Intellij IDEA 使用Spring-boot-devTools无效的问题
- 解决问题 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- 解决spring-boot 中 bean无法注入的问题
- Swagger使用及Springfox+SpringBoot解决404问题
- 解决Genymotion模拟器无法使用问题“the file is currupt”,“uable to boot-please use a kernel appropriate for your c