04: Spring MVC with Thymeleaf and JavaConfigs

Project structure

pom.xml to bring-in Thymeleaf & Spring jars

Step 1: Add “Thymeleaf“jar dependency, and also override default “maven-war-plugin” by explicitly adding the”failOnMissingWebXml” to false to not have web.xml as we will be using JavaConfigs and AbstractAnnotationConfigDispatcherServletInitializer.

Define the model class

Step 2: Define the POJO Login.java as the model inside the package “com.mytutorial.model”.

Define the controller class

Step 3: Define the controller class SimpleLoginController .java in the package “com.mytutorial.controller”.

Define the views as html with Thymeleaf expressions

Step 4: The views login.html & login-success.html with thymeleaf expressions. Created in the “src/main/webapp/WEB-INF/views” folder.


Wire up with Spring JavaConfig & Annotations

Step 5: The Java based Spring config SimpleWebConfiguration.java in the “com.mytutorial.config” package to bootstrap the controller & the view resolver.

Step 6: The Java based Spring config SimpleWebAppInitializer.java in the “com.mytutorial.config” package to bootstrap the SpringDispatcherServlet & the Servlet mapping.

Build simpleWeb.war & deploy to Tomcat

Build “simpleWeb.war” with “mvn clean install”. Copy the war file to Tomcat’s “webapps” folder.

Start the Tomcat server & open a web browser

Start the Tomcat server.



300+ Java Developer Interview Q&As

800+ Java Interview Q&As