velocity 获取文件服务器文件偶尔需要刷新才能加载出来的问题
来源:互联网 发布:mac硬盘恢复 编辑:程序博客网 时间:2024/05/20 19:15
情况如下:使用vm的tool去后台读取配置文件时,有时不生效,需要刷新一下才能加载出来,目前找到下面的解决方式,但是还不确定原因具体是因为什么导致,后续再补充。
代码如下:
springMvc.xml:
<bean id="viewResolver" class="com.yupen.util.vm.YPVelocityViewResolver"> <property name="cache" value="true"/> <property name="prefix" value="/"/> <property name="suffix" value=".vm"/> <property name="contentType" value="text/html;charset=utf-8" /> <property name="layoutUrl" value="layout/default.vm"/> <property name="allowSessionOverride" value="true"/> <property name="allowRequestOverride" value="true"/> <property name="exposeSessionAttributes" value="true"/> <property name="requestContextAttribute" value="rc"/> <property name="exposeRequestAttributes" value="true"/> <property name="viewClass" value="com.yupen.util.vm.YPVelocityView"></property> <property name="toolboxConfigResource" value="classpath:velocity_toolbox.xml"></property></bean>YPVelocityViewResolver:
package com.yupen.util.vm;import org.springframework.core.io.Resource;import org.springframework.web.servlet.view.AbstractUrlBasedView;import org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver;public class YPVelocityViewResolver extends VelocityLayoutViewResolver { private Resource toolboxConfigResource; @Override protected AbstractUrlBasedView buildView(String viewName) throws Exception { YPVelocityView view = (YPVelocityView) super.buildView(viewName); if (this.toolboxConfigResource != null) { view.setToolboxConfigResource(this.toolboxConfigResource); } return view; } public Resource getToolboxConfigResource() { return toolboxConfigResource; } public void setToolboxConfigResource(Resource toolboxConfigResource) { this.toolboxConfigResource = toolboxConfigResource; }}YPVelocityView:
package com.yupen.util.vm;import org.apache.velocity.context.Context;import org.apache.velocity.tools.Scope;import org.apache.velocity.tools.ToolboxFactory;import org.apache.velocity.tools.config.XmlFactoryConfiguration;import org.apache.velocity.tools.view.ViewToolContext;import org.springframework.core.io.Resource;import org.springframework.web.context.support.ServletContextResource;import org.springframework.web.servlet.view.velocity.VelocityLayoutView;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.net.URL;import java.util.Map;public class YPVelocityView extends VelocityLayoutView { private Resource toolboxConfigResource; private static ToolboxFactory factory; @Override protected Context createVelocityContext(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { // return super.createVelocityContext(model, request, response); ViewToolContext context = new ViewToolContext(getVelocityEngine(), request, response, getServletContext()); context.putAll(model); if (null != getToolboxConfigLocation() || null != getToolboxConfigResource()) { synchronized(YPVelocityView.class){ if (factory==null){ XmlFactoryConfiguration cfg = new XmlFactoryConfiguration(); URL url; if (null != getToolboxConfigLocation()) { url = new ServletContextResource(getServletContext(), getToolboxConfigLocation()).getURL(); cfg.read(url); } else if (null != getToolboxConfigResource()) { url = getToolboxConfigResource().getURL(); cfg.read(url); } factory = cfg.createFactory(); } } if (factory!=null){ context.addToolbox(factory.createToolbox(Scope.APPLICATION)); context.addToolbox(factory.createToolbox(Scope.REQUEST)); context.addToolbox(factory.createToolbox(Scope.SESSION)); } } return context; } public void setToolboxConfigResource(Resource toolboxConfigResource) { this.toolboxConfigResource = toolboxConfigResource; } private Resource getToolboxConfigResource() { return toolboxConfigResource; }}
0 0
- velocity 获取文件服务器文件偶尔需要刷新才能加载出来的问题
- [DELVE][web]解决jsp修改后,修改的内容需要重启tomcat才能刷新出来
- Velocity加载文件的奇怪问题
- 有SelectedIndexChanged事件的控件的刷新问题-需要点击两下才能刷新的问题
- webview部分内容偶尔加载不出来,html5在webview渲染问题
- 使用ffmpeg转码的MP4文件需要加载完了才能播放的解决办法
- 使用ffmpeg转码的MP4文件需要加载完了才能播放的解决办法
- velocity中加载模板文件的方式
- windows新建或者重命名文件及文件夹必须手动刷新才能显示出来问题解决方法
- web网站css,js更新后客户浏览器缓存问题,需要刷新才能正常展示的解决办法
- web网站css,js更新后客户浏览器缓存问题,需要刷新才能正常展示的解决办法
- web网站css,js更新后客户浏览器缓存问题,需要刷新才能正常展示的解决办法
- 【转载】----web网站css,js更新后客户浏览器缓存问题,需要刷新才能正常展示的解决办法
- 小米手机加载assests目录下的html文件加载不出来的问题
- 安装sql2000时提示“某个文件被挂起,需要重新启动才能安装”的问题
- 关于mp4文件在IE6-IE8里需要完全缓冲完才能播放的问题
- 【XCode中变更 resource文件后,需要重新编译才能正确识别更新】问题的解决方案
- 偶尔需要
- android 关闭弹出键盘
- 笨鸟先飞——Java基础Map集合学习
- springboot webmvc 自动配置
- ASP.NET基础教程--02
- 《Angular2之TypeScript》
- velocity 获取文件服务器文件偶尔需要刷新才能加载出来的问题
- elk日志分析filebeat配置(filebeat + logstash)
- c语言中sprint的用法
- StringUtils中isEmpty 和isBlank的区别
- xv6源码分析(六):进程调度
- 国外不良资产处置方式
- 算法之路二:刘汝佳算法竞赛入门经典 3.5Tex中的引号 UVa272
- 杭电 2013 ( 蟠桃记 ) java
- Android 代码规范(自用)