Integrating thymeleaf with Spring framework
Note: This is intended for advanced programmers who already knows the spring,Maven, thymeleaf basics.
Thymeleaf will provide view templates for spring web applications like JSP’s.
1. Thymeleaf dependencies configuration
Add following dependencies in pom.xml
<dependency > <groupId> org.thymeleaf</groupId > <artifactId> thymeleaf</artifactId > <version> ${thymeleaf.version}</version > <scope> compile</scope > </dependency> <dependency> <groupId> org.thymeleaf</groupId > <artifactId> thymeleaf-spring3 </artifactId> <version> ${thymeleaf.version}</version > <scope> compile</scope > </dependency> 2. Configure following belans spring applicationContext.xml file. The view resolver will handle all the view request. <bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver"> <property name="prefix" value="/WEB-INF/templates/" /> <property name="suffix" value=".html" /> <property name="templateMode" value="HTML5" /> <!-- Template cache is true by default. Set to false if you want --> <!-- templates to be automatically updated when modified. --> <property name="cacheable" value="true" /> </bean> <bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine"> <property name="templateResolver" ref="templateResolver" /> </bean> <bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver"> <property name="templateEngine" ref="templateEngine" /> </bean>
3. write the template pages to for displaying in web site.