谷歌应用程序引擎的速度框架 [英] velocity framework on google app engine
问题描述
线程main中的异常org.apache.velocity.exception.VelocityException:未能初始化一个实例具有当前运行时配置的org.apache.velocity.runtime.log.ServletLogChute。
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)
(Main.java:10)
引起:java.lang.UnsupportedOperationException:无法检索ServletContext来自应用程序属性
位于org.apache.velocity.runtime.log.ServletLogChute.init(ServletLogChute.java:73)
位于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,获取并初始化引擎* /
VelocityEngine ve = new VelocityEngine();
ve.init();
/ *接下来,获取模板* /
模板t = ve.getTemplate(helloworld.vm);
/ *创建一个上下文并添加数据* /
VelocityContext context = new VelocityContext();
context.put(name,World);
/ *现在将模板渲染成StringWriter * /
StringWriter writer = new StringWriter();
t.merge(context,writer);
/ *显示世界* /
System.out.println(writer.toString());
$ / code $ / pre
$ b $ p 同一个程序在正常的eclipse项目上运行得很好。什么可能是问题?解决方案 似乎只是 ServletLogChute
类需要 ServletContext
,Velocity本身可以完全独立于Servlet环境。
t有一个servelt日志,在调用 ve.init()
之前尝试添加以下内容:
ve.setProperty(runtime.log.logsystem.class,org.apache.velocity.runtime.log.NullLogChute);
...或
/ releases-velocity-1.6.2 / developer-guide.html#Configuring_Loggingrel =noreferreri am trying to use velocity framework on google app engine. i wrote a small program with a main method and tried running it locally. i get the following exception :
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
Here is my program:
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() );
}
}
the same program runs perfectly fine on a normal eclipse project. what could be the problem?
解决方案 Seems to only be the ServletLogChute
class that requires the ServletContext
, Velocity itself can work entirely standalone from a Servlet environment.
Since you obviously don't have a servelt log, try adding the following before you call ve.init()
:
ve.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogChute");
...or check here if you have specific logging requirements.
这篇关于谷歌应用程序引擎的速度框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文