Charles Forsythe's Resume Charles Forsythe's Resume


Download my Resume(PDF)

My Technical Blog My Technical Blog

« Back

Spring MVC Portlet + Freemarker

Search around for any "Spring MVC Porlet" tutorial or draft and you will undoubtly find the phrase "Spring Portlet MVC Framework provides easy integration with popular view-rendering technologies such as JSTL, Apache Tiles, Apache Velocity, and FreeMarker."

The way that Freemarker does this is to instantiate a ViewRenderServlet.  This Servlet can be invoked from the Portlet to use Servlet-oriented view renderers to render the Portlet.  It's a nice hack, and your can find dozens of examples where it is demonstrated with JSTL.  This is a problem because if you modify the example to use Freemarker, it doesn't work.  It doesn't work because of the way that the FreemarkerView class relies on auto-wiring to configure it.  What you will get in the logs is this:

	        at org.spring(...)FreeMarkerView.getTemplate(
	        at org.spring(...)FreeMarkerView.checkResource(
	        at org.spring(...)UrlBasedViewResolver.loadView(

I found a 2-year-old bug report about this claiming that the Freemarker renderer simply wouldn't work with Portlets and that maybe they'd fix that in Spring 3.1.  It turns out that the system works fine if you initialize it correctly.  In order to do so, you must include the following in your web.xml:


I had already figured this out myself, but was still searching for a fix because my FTL referenced "hellowWorldMesssage" when it was being passed "helloWorldMessage" (look carefully to see the difference).  Now that I'm set up with my favorite rendering pipeline, I'm wondering how many more hacks I'll need to do to get Freemarker to work well in a Portlet environment.

Trackback URL:

I have tried your approach but I am still getting the NullPointerException:

<web-app id="WebApp_ID" version="2.4" xmlns="" xmlns:xsi="" xsi:schemaLocation="">





Any help will be very much appreciated.
Posted on 12/31/12 8:39 AM.
I've just discovered that LifeRay's blog applet doesn't automatically subscribe me to comments, so I'm answering this months after it was posted.

Emmanuel doesn't tell me what LifeRay stack he's using, but I'm guessing LifeRay 6.1.1 on Tomcat. Why am I guessing that? Because it broke my fix. Here's an new fix:­ing-and-freemarker-quick-fix-edition
Posted on 3/13/13 5:19 AM in reply to Emmanuel.

Hello World Hello World

Welcome to Liferay Portal Community Edition 6.1.0 CE (Paton / Build 6100 / January 6, 2012).

Publications Publications

Instant FreeMarker Starter

Instant Freemarker StarterThe Instance Freemarker Starter offers a quick introduction to using Freemarker in Enterprise projects. All of the key features of Freemarker Template Language (FTL) are covered with realistic examples. Also covered are integration with MVC frameworks such as Spring.


The Know-it-All Guide to java.langString

This guide provides a detailed description of how to work with Java's most-common class.  This included issues affecting memory usage, internationalization (i18n) and character encoding.

Second Edition: Now updated for Java 8!

(This has been taken offline for further edits)