JFinal学习过程中遇到异常:java.lang.ClassNotFoundException: freemarker.template.TemplateException

shouyong 发布于 2014/06/29 22:41
阅读 12K+
收藏 0

没有配置Handler,只是配置Router


/* (non-Javadoc)
	 * @see com.jfinal.config.JFinalConfig#configRoute(com.jfinal.config.Routes)
	 */
	@Override
	public void configRoute(Routes me) {
		me.add(new RootRoutes());
		me.add(new TxtRoutes());
	}




URL:

http://127.0.0.1/txt/search/abc-devc

log显示如下:

JFinal action report -------- 2014-06-29 22:29:52 ------------------------------
Controller  : net.xxx.web.txt.control.SearchController.(SearchController.java:1)
Method      : index
UrlPara     : abc-devc

浏览器输出:

HTTP ERROR 500

Problem accessing /txt/search/abc-devc. Reason:

    freemarker/template/TemplateException
Caused by:

java.lang.NoClassDefFoundError: freemarker/template/TemplateException
	at com.jfinal.render.RenderFactory.getDefaultRender(RenderFactory.java:173)
	at com.jfinal.core.ActionHandler.handle(ActionHandler.java:91)
	at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
	at org.eclipse.jetty.server.Server.handle(Server.java:365)
	at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
	at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926)
	at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635)
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
	at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
	at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.ClassNotFoundException: freemarker.template.TemplateException
	at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:430)
	at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:383)
	... 27 more
Caused by:

java.lang.ClassNotFoundException: freemarker.template.TemplateException
	at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:430)
	at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:383)
	at com.jfinal.render.RenderFactory.getDefaultRender(RenderFactory.java:173)
	at com.jfinal.core.ActionHandler.handle(ActionHandler.java:91)
	at net.xxx.web.ResourceHandler.handle(ResourceHandler.java:23)
	at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
	at org.eclipse.jetty.server.Server.handle(Server.java:365)
	at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
	at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926)
	at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635)
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
	at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
	at java.lang.Thread.run(Thread.java:744)



加载中
0
JFinal
JFinal
添加 freemarker 的 jar 包进去,在  http://www.jfinal.com 可以下载到所有 jar 包
0
shouyong
shouyong

引用来自“JFinal”的评论

添加 freemarker 的 jar 包进去,在  http://www.jfinal.com 可以下载到所有 jar 包
问题解决,是

	public void index() {
		String para = getPara(0);
		if (para == null || para.length() < 1) {
			throw new RuntimeException();
		}
		if (getPara(1) == null || (getPara(1) != null && getPara(1).equalsIgnoreCase("v1"))) {
			....
			renderText(ret);
		}else{
		renderNull(); //漏了这个。
}
	}

我不知道为什么会这样,我跟了下源码,不太明白。如果没有加renderNull()会报这个错误??




shouyong
shouyong
回复 @JFinal : 另外请教个问题,不知道是否有基于JFinal的开源论坛?我这边有个这方面需求。
shouyong
shouyong
回复 @JFinal : 感谢。 理解了。
JFinal
JFinal
回复 @chensy : 报错是因为缺少 freemarker.jar 这个包,这样设计可以通过约定的方式而不去写 render 这行代码,代码量可以少到极致
shouyong
shouyong
回复 @JFinal : 我尝试过me.setViewType(ViewType.FREE_MARKER)及其它几种模式,这么完全没用。 这种情况下,即使是给默认的render也不应该报错。 烦请指点,这种设计是基于何种考虑呢?
JFinal
JFinal
因为请求没有走第二个 if , 所以就没有调用 renderText,当没有调用任何 render 的时候,jfinal 会默认给你调用一个,规则是:render(controllerKey + methodName);
返回顶部
顶部