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 spring–boot–starter–thymeleaf 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 :
- http://www.christophlorenz.de/blog/learnings-with-spring-boot-and-thymeleaf/
- http://www.thymeleaf.org/documentation.html
Tagged: Project Structure, Spring, Spring boot, Thymeleaf
Leave a Reply