当前位置:  开发笔记 > 编程语言 > 正文

谷歌应用引擎上的速度框架

如何解决《谷歌应用引擎上的速度框架》经验,为你挑选了1个好方法。

我想在谷歌应用程序引擎上使用速度框架.我用main方法编写了一个小程序,并尝试在本地运行它.我得到以下异常:

Exception in thread "main" org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.ServletLogChute with the current runtime configuration.
  at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:206)
  at org.apache.velocity.runtime.log.LogManager.updateLog(LogManager.java:255)
  at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:795)
  at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:250)
  at org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:107)
  at Main.main(Main.java:10)
Caused by: java.lang.UnsupportedOperationException: Could not retrieve ServletContext from application attributes
  at org.apache.velocity.runtime.log.ServletLogChute.init(ServletLogChute.java:73)
  at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:157)
  ... 5 more

这是我的计划:

import java.io.StringWriter;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;

public class Main {
 public static void main(String[] args) throws Exception{
        /*  first, get and initialize an engine  */
        VelocityEngine ve = new VelocityEngine();
        ve.init();
        /*  next, get the Template  */
        Template t = ve.getTemplate( "helloworld.vm" );
        /*  create a context and add data */
        VelocityContext context = new VelocityContext();
        context.put("name", "World");
        /* now render the template into a StringWriter */
        StringWriter writer = new StringWriter();
        t.merge( context, writer );
        /* show the World */
        System.out.println( writer.toString() );    
 }
}

相同的程序在正常的eclipse项目上运行得非常好.可能是什么问题呢?



1> Will Prescot..:

似乎只是需要的ServletLogChuteServletContext,Velocity本身可以完全独立于Servlet环境.

由于您显然没有servelt日志,请在调用之前尝试添加以下内容ve.init():

ve.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogChute");

...或者如果您有特定的记录要求,请在此处查看.

推荐阅读
李桂平2402851397
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有