把应用打成war包发布在Weblogic上时出现找不到velocity模板,异常:Unable to find resource '/template/simple/hidden.vm' (以目录方式发布到Weblogic上,不存在此问题)
经过排查,问题出现在资源的加载方式上,解决问题的方法是,为应用增加加载资源的方法,webwork已经提供了一个在classpath加载资源的类WebWorkResourceLoader (该类继承了velocity提供的ClasspathResourceLoader),因此只需要在velocity的配置文件中修改配置。
#默认的设置
#resource.loader = file
#file.resource.loader.description = Velocity File Resource Loader
#file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader
#file.resource.loader.path = .
#file.resource.loader.cache = false
#file.resource.loader.modificationCheckInterval = 2
#修改完的
resource.loader = class
class.resource.loader.class = com.opensymphony.webwork.views.velocity.WebWorkResourceLoader
默认情况下,webwork会加载类路径下的velocity.properties,当然velocity.properties的路径也可以自定义,只需要在webwork.properties的webwork.velocity.configfile属性中配置
### Location of velocity.properties file. defaults to velocity.properties
#webwork.velocity.configfile = velocity.properties
测试时发现配置完的velocity.properties并没有被加载,查看源代码发现原因是出在webwork的实现上,同时webwork也支持自定义的扩展,因此我们可以扩展webwork的实现。如:自定义类MyVelocityManager继承VelocityManager.
public class MyVelocityManager extends VelocityManager {
private static final Log log = LogFactory.getLog(EcsSalesVelocityManager.class);
private String configfile = "velocity.properties";
@Override
public Properties loadConfiguration(ServletContext context) {
Properties properties = super.loadConfiguration(context);
if (Configuration.isSet("webwork.velocity.configfile")) {
configfile = Configuration.getString("webwork.velocity.configfile");
}
configfile = configfile.trim();
InputStream inStream = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(configfile);
try {
properties.load(inStream);
}
catch (IOException e) {
log.warn("Unable to load velocity configuration file '" + configfile + "'", e);
}
return properties;
}
}
我们需要在webwork.properties中自定义该类的路径
#扩展的VelocityManager
webwork.velocity.manager.classname = com.opensymphony.webwork.views.velocity.ext.MyVelocityManager
分享到:
相关推荐
Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎
Velocity模板实例 Velocity模板实例 Velocity模板实例 Velocity模板实例
Velocity模板入门简单DEMO, 代码有注解;
Velocity模板技术语法详细介绍,包括很详细的示例代码 1.变量………………………………………………………………………………1 2.循环………………………………………………………………………………2 3.条件语句...
Velocity.js 是velocity模板语法的javascript实现。Velocity 是基于Java的模板引擎,广泛应用在阿里集 体各个子公司。Velocity模板适用于大量模板使用的场景,支持复杂的逻辑运算,包含 基本数据类型、变量赋值和...
SpringBoot集成Mybatis,velocity模板
史上最全Velocity模板使用指南中文版,适合初学者读阅
Velocity模板解析,通过Velocity模板自动替换表达式中的变量
Velocity实现模板
Velocity模板(VM)语言介绍,简单的介绍,方便入门!
SpringBoot集成Mybatis,velocity模板展示数据
Velocity应用案例,Velocity夹包文件
多视图渲染JspModelAndView,XmlModelAndView,TextStreamModelAndView,Velocity),还可自行定义渲染. 方便的验证和异常处理机制 http://download.csdn.net/source/1373612 源程序 请下载过的受好者留下QQ:方便联系
velocity是一个很实用的页面工具,相对于jsp更便于开发维护,本文档是他的一个基础使用工具,便于比更快学习使用velocity!
velocity-web模板工具, 参考:http://blog.csdn.net/nature_fly088/article/details/52497779 和http://www.ibm.com/developerworks/cn/java/j-lo-velocity1/
将将附件velocity1.6.zip解压后的文件夹放在\%你的myeclipse安装目录%\\Genuitec\Common\plugins 目录下。 打开\%你的myeclipse安装目录%\Genuitec\MyEclipse 8.5\configuration\org.eclipse.equinox....
开发velocity所需的jar包
velocity模板访问velocity模板访问velocity模板访问