"Welcome To Ashok IT" "Spring Boot and MicroServices" Topic : Spring Boot MVC - Introduction Date : 15/05/2025 (Session - 47) _____________________________________________________________________________________________________________________________ Spring Boot MVC =============== * Spring Boot MVC is umbrella project of Spring Boot. * Spring Boot MVC We can develop either WebApplications (or) Distributed Applications. * Spring Boot automatically configures spring application based on starter selection(DependencyManagement,SpringBeans etc.,) * Typically in spring MVC driven application lot of configuration such as DispatcherServlet,View Resolvers,datasource,transaction management etc., * Spring Boot MVC Module will auto configure the DispatcherServlet if spring mvc jar is present in the classpath. * It will auto configures the Jackson library if the jackson jar present in the classpath. * It will auto configures the data source if Hibernate jar present in the classpath. * Spring Boot Provides the "spring-boot-starter-web" for developing the webapplication using Spring MVC. * Spring Boot autoconfiguration registers and configures the DispatcherServlet automatically. There fore, we don't need to register the DispatcherServlet manually. * While working with Spring Boot MVC we no need to install the Server for testing webapplication because spring boot mvc supports Embedded servers(Tomcat,Jetty) (or) external servers. Project Creation ================= 1) Switch to STS IDE and Create new project with below parameters Packaging Mode :: JAR(Testing through Embedded Servers), WAR(Testing through Embedded Servers,External servers) :: WAR (Recommended) 2) Starter Selection : We need to select the web starter by searching word as "web" then you will find option called "Spring web" check the checbox and click on "Finish" button then Project will be created 3) Understanding Folder Structure src/main/resource | ------ static -------------> For placing static resources(images,audios,videos,css,Javascript files etc.,) | ------ templates -----------> For placing Thymeleaf pages. | ------ application.properties ------------> application level configuration entries 4) Observed the Jar files under "mavend dependencies". i.e.,spring mvc,jackson,embedded tomcat etc., 5) Added some folders under standard folder(webapp) webapp >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Standard folder |- >>>>>>>>>>>>>>>> WEB-INF >>>>>>>>>>>>>> standard folder |- >>>>>>>>>>>>>>>> views >>>>>>>>>>>>>>>>> Non-Standard folder. 6) Execute the boot Application by selecting Application.java Run as >>>> Spring Boot Application Error ===== *************************** APPLICATION FAILED TO START *************************** Description: Web server failed to start. Port 8080 was already in use. 7) We can have option to change the port no for embedded server in application.properties application.properties ======================= server.port=1234 8) After adding port number try to run the Spring Boot Application again. Spring boot First Application ============================= 1) Created the Sample Controller by adding two Request Processor Methods in Spring Boot MVC Application package com.ashokit.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; @Controller public class WelcomeController { @RequestMapping(value="/wishes", method=RequestMethod.GET) public String generateWelcomeMessage(Model model) { model.addAttribute("Message", "Welcome To Ashok IT For Spring Boot MVC Development....."); return "welcome"; } @GetMapping(value = "/wishByUser") public ModelAndView generateWishesByUser(@RequestParam("username") String username) { ModelAndView mav = new ModelAndView("welcome"); mav.addObject("wishMessage",String.format("Welcome To Ashok IT For Spring Boot MVC Development ...%s", username)); return mav; } } 2) Created the welcome.jsp under the views folder welcome.jsp ========== <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix = "c" uri="http://java.sun.com/jsp/jstl/core" %>