代码之家  ›  专栏  ›  技术社区  ›  Aadith Ramia

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

  •  5
  • Aadith Ramia  · 技术社区  · 15 年前

    我正在尝试在谷歌应用引擎上使用速度框架。我用一个主方法编写了一个小程序,并尝试在本地运行它。我得到以下例外:

    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项目上运行得非常好。有什么问题?

    3 回复  |  直到 13 年前
        1
  •  9
  •   Will Prescott    15 年前

    似乎只有 ServletLogChute 需要 ServletContext ,Velocity本身可以完全独立于servlet环境工作。

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

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

    或… check here if you have specific logging requirements .

        2
  •  2
  •   Carl Smotricz    15 年前

    这可能不是世界末日和故事,但有一个与GAE兼容的软件列表:

    http://groups.google.com/group/google-appengine-java/web/will-it-play-in-app-engine

    我在里面找不到速度。有可能人们只是忘记了测试并将其包含在列表中,但也有可能是Velocity带来了一些API,这些API与GAE的配合不太好。

        3
  •  2
  •   A. Ionescu    14 年前

    速度可以确定地在gae/j上运行。

    Apache Click 使用Velocity作为模板引擎的框架在GAE/J上没有问题。

    当然需要一个 different configuration 因为gae/j是一个约束环境,所以它比通常情况下更有效。