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.

Login.html
Login-success.html

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.

http://localhost:8080/simpleWeb/entry/

http://localhost:8080/simpleWeb/entry/login


Why & What are the benefits

🎯 Why java-success.com?

🎯 What are the benefits of Q&As approach?

Learn by categories such as FAQs – Core Java, Key Area – Low Latency, Core Java – Java 8, JEE – Microservices, Big Data – NoSQL, Architecture – Distributed, Big Data – Spark, etc. Some posts belong to multiple categories.

800+ Java & Big Data Q&As Menu

Top