Spring Boot MVC with Tiles and AJAX

In my previous tutorials I have shown how to create a Spring Boot MVC application, here I will show you how to create an AJAX based Spring Boot MVC application with Tiles.

What is Tiles (https://tiles.apache.org/)

A free open-sourced templating framework for modern Java applications.
Based upon the Composite pattern it is built to simplify the development of user interfaces.

For complex web sites it remains the easiest and most elegant way to work alongside any MVC technology.

In summary, tiles allows authors to define page fragments which can be assembled into a complete pages at runtime. These fragments, or tiles, can be used as simple includes in order to reduce the duplication of common page elements or embedded within other tiles to develop a series of reusable templates. These templates streamline the development of a consistent look and feel across an entire application.


The following configurations are required in order to run the application

Eclipse Kepler
JDK 1.8
Tomcat 8
Have maven 3 installed and configured
Spring 4, Tiles dependencies in pom.xml

Now we will see the below steps how to create a maven based project in Eclipse

Step 1. Create a maven based web project in Eclipse

Go to File -> New -> Other. On popup window under Maven select Maven Project. Then click on Next. Select the workspace location – either default or browse the location. Click on Next. Now in next window select the row as highlighted from the below list of archtypes and click on Next button.


Now enter the required fields (Group Id, Artifact Id) as shown below

Group Id : com.roytuts
Artifact Id : spring-boot-tiles-ajax

Step 2. Modify the pom.xml file as shown below.

Step 3. If you see JRE System Library[J2SE-1.5] then change the version by below process

Do right-click on the project and go to Build -> Configure build path, under Libraries tab click on JRE System Library[J2SE-1.5], click on Edit button and select the appropriate jdk 1.8 from the next window. Click on Finish then Ok.

Change also the Compiler compliance level as 1.8 from Java -> Compiler.

Step 4. Now when the build process finished then delete web.xml file from WEB-INF

Step 5. Create application.properties file put under src/main/resources

Step 6. Create a directory called layouts under src/main/webapp directory for putting jsp views, then put below template.jsp file

Step 7. Create a directory called tiles under src/main/webapp directory for putting jsp views, then put below files inside this folder.




Step 8. Create a directory called views under src/main/webapp directory for putting jsp views, then put below files under it



Step 9. Create a tiles definition XML file, tiles.xml, then put it in WEB-INF directory. You can read about tiles definition here https://tiles.apache.org/framework/tutorial/basic/pages.html

Step 10. Create a tiles configuration class with below source code because we are not going to create web.xml file in Spring Boot application so that we could have put it in web.xml file

Step 11. Create a model class Contact.java

Step 12. Create MySQL table contact in database roytuts

Step 13. Create a row mapper class which will map Contact object to each row of database table

Step 14. Create a DAO interface

Step 15. Create a DAO interface implementation class. Here I have used NamedParameterJdbcTemplate so that I can map Contact class attribute with table column.

Step 16. Create a Service interface.

Step 17. Create a Service interface implementation class.

Step 18. Create a Spring Controller

Step 19. Create a Spring Boot main class for starting up the application

Step 20. Now run the above class and once the main class successfully runs, then hit the below URL in the browser


spring boot mvc tiles ajax

Step 21. Now hit URL http://localhost:8080/contact or click on Contact Here link on home page in the browser and filled input fields and click on Save Contact button.

spring boot mvc tiles ajax

The value gets saved in the database successfully

spring boot mvc tiles ajax

Thanks for reading.


Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.