How to configure Templating Solution Engine SiteMesh with Spring boots

19 / May / 2016 by Sandeep Gupta 0 comments

SiteMesh is a very simple, lightweight & flexible Templating Solution framework for Java Web applications. SiteMesh can be used in lot more ways if we combine it with Spring boot framework. Configuring the SiteMesh with Spring Boot is little bit tricky but not complex, as we need to create a custom filter and then inject it into Filter Chain to work properly.

Here We will be refering to a Gradle based Spring Boot application, with which SiteMesh needs to be integrated. Detailed functionality of SiteMesh is not covered here. The focus area is SiteMesh integration with Spring Boot.

Following are the 4 Steps for integration:

1. Add gradle dependency in spring boot project’s gradle file


2. Create one or more templates or decorators to apply

<!DOCTYPE html>
<html lang="en">
< sitemesh:write property="head" />
<%@ include file="/WEB-INF/includes/header.jsp" %>
<%@ include file="/WEB-INF/includes/topNavigation.jsp" %>
<main id="page-wrapper5">
<div class="container-fluid">
<sitemesh:write property="body" />

3. Create SiteMesh filter. Register multiple decorators. We can also exclude paths if required.

public class CustomSiteMeshFilter extends ConfigurableSiteMeshFilter {
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
// Assigning default decorator if no path specific decorator found
builder.addDecoratorPath("/*", "/WEB-INF/sitemesh/MainDecorator.jsp")
// Map decorators to specific path patterns.
.addDecoratorPath("/login", "/WEB-INF/sitemesh/simpleDecorator .jsp")
// Exclude few paths from decoration.

4. Inject SiteMesh filter in SpringSecurityChain. Url Patterns identifies the candidates which should be wrapped with decorator. Here we are applying the decorators to all URLs and handling exclusions in SiteMeshFilter

public class ServletInit extends SpringBootServletInitializer {
public FilterRegistrationBean siteMeshFilter() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new CustomSiteMeshFilter()); // adding sitemesh filter ??
return filter;


Leave a Reply

Your email address will not be published. Required fields are marked *