Upgrade from Tiles 2 to Tiles 3 on Spring MVC 3 application


Dev-Bookmarks Logo

Save up to a workweek a year by efficiently managing your dev bookmarks, on www.bookmarks.dev. Share your favorites with the community and they will be published on Github - Star


I’ve just upgraded the web application that powers Podcastpedia.org to use Apache Tiles 3 instead of Tiles 2. I am particularly interested in the Tiles integration with Velocity for email generation.

Note: You need at least the Spring 3.2 release for this to work.

This occured in three small steps:

  1. upgrade maven dependencies
  2. upgrade tiles elements in the Spring application context
  3. upgrade tiles dtd version

1. Upgrade maven dependencies

What I had to do was just replace the ${tiles.version} in the maven pom.xml file from 2.2.2 to 3.0.1 for the Tiles dependencies I use, and now it looks like this:

<dependency>
			<groupId>org.apache.tiles</groupId>
			<artifactId>tiles-extras</artifactId>
			<version>${tiles.version}</version>
		</dependency>

		<dependency>
			<groupId>org.apache.tiles</groupId>
			<artifactId>tiles-jsp</artifactId>
			<version>${tiles.version}</version>
		</dependency>

		<dependency>
			<groupId>org.apache.tiles</groupId>
			<artifactId>tiles-servlet</artifactId>
			<version>${tiles.version}</version>
		</dependency>	
		<dependency>
			<groupId>org.apache.tiles</groupId>
			<artifactId>tiles-template</artifactId>
			<version>${tiles.version}</version>
		</dependency>	
		<dependency>
			<groupId>org.apache.tiles</groupId>
			<artifactId>tiles-el</artifactId>
			<version>${tiles.version}</version>
		</dependency>

2. Upgrad Tiles configuration in Spring application context

The next thing was to upgrade to version 3 the tilesViewResolver and tilesConfigurer in the Spring application context:

....................
<!-- Convenience subclass of UrlBasedViewResolver that supports TilesView (i.e. Tiles definitions) and custom subclasses of it. -->
<!-- Don't forget to set the order if you declared other ViewResolvers 
-->    
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
	<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" />
	<property name="order" value="#{contentNegotiatingResolver.order+1}" />
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
  <property name="basename" value="views"/>
  <property name="order" value="#{tilesViewResolver.order+1}" />
</bean>

<!-- Helper class to configure Tiles 2.x for the Spring Framework -->
<!-- See http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/servlet/view/tiles2/TilesConfigurer.html -->
<!-- The actual tiles templates are in the tiles-definitions.xml  -->

<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">	
	<property name="definitions">		
		<list>
			<value>/WEB-INF/tile-defs/templates.xml</value>
			<value>/WEB-INF/tile-defs/definitions.xml</value>
		</list>		
	</property>	
</bean>
....................

3. Upgrade tiles.dtd version

In the Tiles definitions templates upgrade to Tiles 3.0 dtd

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">        
<tiles-definitions>  
.........         
</tiles-definitions>

That’s it.

P.S.

For a complete example of Tiles integration with Spring MVC see my post – Spring 3 and Tiles 2 Integration

Lots of exciting dev bookmarks added in march 2019

Lots of exciting dev #bookmarks added in march 2019. Keywords: alias, api, api-management, architecture, arquillian, async, asynchronous, awesome, awesome-list, aws, bash, bootstrap, c, chai, cheatsheet, circuit-breaker, css, devops, diagnostics, diagram, dns, docker, docker-compose, docs, documentation, domain-driven-design, dotfiles, email, error-handling, facebook, favicon, ffmpeg, free-programming-books, functional-programming, gif, git, gradle, graph, helm, homebrew, html, html5, immutable.js, install, integration-testing, istio, java, javascript, jenv, junit, jvm, kotlin, kubernetes, kubernetes-helm, latex, linux, macos, markdown, maven-plugin, microservices, middleware, mocha, mongodb, monitoring, nginx, nodejs, oidc, online-tools, open-source, openid-connect, osx, package-manager, pandoc, performance, podcast, promise, proxy, r, reactive, reactive-programming, reactjs, redis, resources, rest, rxjs, security, shell, spring, spring-boot, spring-cloud, spring-cloud-gateway, spring-security, spring-webflux, sql, testing, tools, user-experience, video-processing, vim, visualization, web, websocket, windows and zuul Continue reading