Thymeleaf Hello World – day 1 – Project Structure

Developing application using Spring boot and Thymeleaf is simpler and quick, if you follow these convention. Thymeleaf requires a specific project structure which helps to render views and refer items without getting into error.

Since we are using Spring Boot, because we’ve included the dependency springbootstarterthymeleaf in our Maven POM for the project, so Spring Boot will do some things automatically for us.

Templates/Fragments

By default, Spring Boot configures the Thymeleaf template engine to read template files from src/main/resources/templates .

Effectively, you as the developer just need to start making Thymeleaf templates and dropping them into  src/main/resources/templates.

Static Resources

It includes libraries and their respective javascript (*.js) and stylesheets (*.css) files to be placed inside src/main/resources/static

 

Project Structure/Convention

  • Messages to placed inside src/main/resources/messages into the message.properties
  • It requires static web content to be placed inside src/main/resources/static (this will be the root directory for your web application for static content like images, CSS and JavaScript files)
  • Most importantly templates must go into src/main/resources/templates and if required, subdirectories there.

Be clean on configuration

  • Use src/main/resources/application.properties as few as possible
  • Use src/main/resources/applicationContext.xml as few as possible
  • Try to use annotation-based configuration as much as possible

All those points are very important, if you don’t follow them, you will get into trouble when you try to run your application standalone and not from your IDE!

Reference :

  1. http://www.christophlorenz.de/blog/learnings-with-spring-boot-and-thymeleaf/
  2. http://www.thymeleaf.org/documentation.html
Advertisements

Tagged: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: