
Domains
Agile Management
Master Agile methodologies for efficient and timely project delivery.
View All Agile Management Coursesicon-refresh-cwCertifications
Scrum Alliance
16 Hours
Best Seller
Certified ScrumMaster (CSM) CertificationScrum Alliance
16 Hours
Best Seller
Certified Scrum Product Owner (CSPO) CertificationScaled Agile
16 Hours
Trending
Leading SAFe 6.0 CertificationScrum.org
16 Hours
Professional Scrum Master (PSM) CertificationScaled Agile
16 Hours
SAFe 6.0 Scrum Master (SSM) CertificationAdvanced Certifications
Scaled Agile, Inc.
32 Hours
Recommended
Implementing SAFe 6.0 (SPC) CertificationScaled Agile, Inc.
24 Hours
SAFe 6.0 Release Train Engineer (RTE) CertificationScaled Agile, Inc.
16 Hours
Trending
SAFe® 6.0 Product Owner/Product Manager (POPM)IC Agile
24 Hours
ICP Agile Certified Coaching (ICP-ACC)Scrum.org
16 Hours
Professional Scrum Product Owner I (PSPO I) TrainingMasters
32 Hours
Trending
Agile Management Master's Program32 Hours
Agile Excellence Master's ProgramOn-Demand Courses
Agile and ScrumRoles
Scrum MasterTech Courses and Bootcamps
Full Stack Developer BootcampAccreditation Bodies
Scrum AllianceTop Resources
Scrum TutorialProject Management
Gain expert skills to lead projects to success and timely completion.
View All Project Management Coursesicon-standCertifications
PMI
36 Hours
Best Seller
Project Management Professional (PMP) CertificationAxelos
32 Hours
PRINCE2 Foundation & Practitioner CertificationAxelos
16 Hours
PRINCE2 Foundation CertificationAxelos
16 Hours
PRINCE2 Practitioner CertificationSkills
Change ManagementMasters
Job Oriented
45 Hours
Trending
Project Management Master's ProgramUniversity Programs
45 Hours
Trending
Project Management Master's ProgramOn-Demand Courses
PRINCE2 Practitioner CourseRoles
Project ManagerAccreditation Bodies
PMITop Resources
Theories of MotivationCloud Computing
Learn to harness the cloud to deliver computing resources efficiently.
View All Cloud Computing Coursesicon-cloud-snowingCertifications
AWS
32 Hours
Best Seller
AWS Certified Solutions Architect - AssociateAWS
32 Hours
AWS Cloud Practitioner CertificationAWS
24 Hours
AWS DevOps CertificationMicrosoft
16 Hours
Azure Fundamentals CertificationMicrosoft
24 Hours
Best Seller
Azure Administrator CertificationMicrosoft
45 Hours
Recommended
Azure Data Engineer CertificationMicrosoft
32 Hours
Azure Solution Architect CertificationMicrosoft
40 Hours
Azure DevOps CertificationAWS
24 Hours
Systems Operations on AWS Certification TrainingAWS
24 Hours
Developing on AWSMasters
Job Oriented
48 Hours
New
AWS Cloud Architect Masters ProgramBootcamps
Career Kickstarter
100 Hours
Trending
Cloud Engineer BootcampRoles
Cloud EngineerOn-Demand Courses
AWS Certified Developer Associate - Complete GuideAuthorized Partners of
AWSTop Resources
Scrum TutorialIT Service Management
Understand how to plan, design, and optimize IT services efficiently.
View All DevOps Coursesicon-git-commitCertifications
Axelos
16 Hours
Best Seller
ITIL 4 Foundation CertificationAxelos
16 Hours
ITIL Practitioner CertificationPeopleCert
16 Hours
ISO 14001 Foundation CertificationPeopleCert
16 Hours
ISO 20000 CertificationPeopleCert
24 Hours
ISO 27000 Foundation CertificationAxelos
24 Hours
ITIL 4 Specialist: Create, Deliver and Support TrainingAxelos
24 Hours
ITIL 4 Specialist: Drive Stakeholder Value TrainingAxelos
16 Hours
ITIL 4 Strategist Direct, Plan and Improve TrainingOn-Demand Courses
ITIL 4 Specialist: Create, Deliver and Support ExamTop Resources
ITIL Practice TestData Science
Unlock valuable insights from data with advanced analytics.
View All Data Science Coursesicon-dataBootcamps
Job Oriented
6 Months
Trending
Data Science BootcampJob Oriented
289 Hours
Data Engineer BootcampJob Oriented
6 Months
Data Analyst BootcampJob Oriented
288 Hours
New
AI Engineer BootcampSkills
Data Science with PythonRoles
Data ScientistOn-Demand Courses
Data Analysis Using ExcelTop Resources
Machine Learning TutorialDevOps
Automate and streamline the delivery of products and services.
View All DevOps Coursesicon-terminal-squareCertifications
DevOps Institute
16 Hours
Best Seller
DevOps Foundation CertificationCNCF
32 Hours
New
Certified Kubernetes AdministratorDevops Institute
16 Hours
Devops LeaderSkills
KubernetesRoles
DevOps EngineerOn-Demand Courses
CI/CD with Jenkins XGlobal Accreditations
DevOps InstituteTop Resources
Top DevOps ProjectsBI And Visualization
Understand how to transform data into actionable, measurable insights.
View All BI And Visualization Coursesicon-microscopeBI and Visualization Tools
Certification
24 Hours
Recommended
Tableau CertificationCertification
24 Hours
Data Visualization with Tableau CertificationMicrosoft
24 Hours
Best Seller
Microsoft Power BI CertificationTIBCO
36 Hours
TIBCO Spotfire TrainingCertification
30 Hours
Data Visualization with QlikView CertificationCertification
16 Hours
Sisense BI CertificationOn-Demand Courses
Data Visualization Using Tableau TrainingTop Resources
Python Data Viz LibsCyber Security
Understand how to protect data and systems from threats or disasters.
View All Cyber Security Coursesicon-refresh-cwCertifications
CompTIA
40 Hours
Best Seller
CompTIA Security+EC-Council
40 Hours
Certified Ethical Hacker (CEH v12) CertificationISACA
22 Hours
Certified Information Systems Auditor (CISA) CertificationISACA
40 Hours
Certified Information Security Manager (CISM) Certification(ISC)²
40 Hours
Certified Information Systems Security Professional (CISSP)(ISC)²
40 Hours
Certified Cloud Security Professional (CCSP) Certification16 Hours
Certified Information Privacy Professional - Europe (CIPP-E) CertificationISACA
16 Hours
COBIT5 Foundation16 Hours
Payment Card Industry Security Standards (PCI-DSS) CertificationOn-Demand Courses
CISSPTop Resources
Laptops for IT SecurityWeb Development
Learn to create user-friendly, fast, and dynamic web applications.
View All Web Development Coursesicon-codeBootcamps
Career Kickstarter
6 Months
Best Seller
Full-Stack Developer BootcampJob Oriented
3 Months
Best Seller
UI/UX Design BootcampEnterprise Recommended
6 Months
Java Full Stack Developer BootcampCareer Kickstarter
490+ Hours
Front-End Development BootcampCareer Accelerator
4 Months
Backend Development Bootcamp (Node JS)Skills
ReactOn-Demand Courses
Angular TrainingTop Resources
Top HTML ProjectsBlockchain
Understand how transactions and databases work in blockchain technology.
View All Blockchain Coursesicon-stop-squareBlockchain Certifications
40 Hours
Blockchain Professional Certification32 Hours
Blockchain Solutions Architect Certification32 Hours
Blockchain Security Engineer Certification24 Hours
Blockchain Quality Engineer Certification5+ Hours
Blockchain 101 CertificationOn-Demand Courses
NFT Essentials 101: A Beginner's GuideTop Resources
Blockchain Interview QsProgramming
Learn to code efficiently and design software that solves problems.
View All Programming Coursesicon-codeSkills
Python CertificationInterview Prep
Career Accelerator
3 Months
Software Engineer Interview PrepOn-Demand Courses
Data Structures and Algorithms with JavaScriptTop Resources
Python TutorialWeb Development
4.7 Rating 50 Questions 25 mins read8 Readers

Spring MVC is a popular Java-based web development framework. The MVC in Spring MVC stands for Model-View-Controller, a design pattern that separates the application into three main components: the model, the view, and the controller.
It is a lightweight alternative to other Java web frameworks such as JSF and Struts. It provides excellent support for RESTful web services and a comprehensive set of tools for working with data binding, validation, flow control, and internationalization.
One of the key benefits of using the Spring MVC framework is its flexibility. The framework is designed to be easily extended and customized. For example, you can add your own custom interceptors or converters to the framework. You can also take advantage of the numerous third-party extensions that are available for Spring MVC.
Another benefit of using Spring MVC is its ease of use. The framework provides a consistent programming model across different types of applications. This makes it easier for developers to learn and use the framework. In addition, Spring MVC includes a wide range of features that can be easily configured without changing application code.
As an open source framework, Spring MVC is well supported by the community and there is a large number of resources available online, including tutorials, books, and articles. The Spring team is also very responsive to questions and issues raised by users. With so much to offer, it's no wonder that Spring MVC is one of the most popular web development frameworks available today and a good choice for a project.
There are three ways to return data from a controller to a view in Spring MVC: Model, ModelMap and ModelAndView.
Model is a simple abstraction for representing data in Spring MVC. It can be used as a replacement for using a Map to store data attributes, with the advantage that it is easier to use and provides more methods for accessing and manipulating data attributes.
@GetMapping("/showViewPage")
public String passParametersWithModel(Model model) {
Map<String, String> map = new HashMap<>();
map.put("spring", "mvc");
model.addAttribute("message", "Baeldung");
model.mergeAttributes(map);
return "viewPage";
} ModelMap is an extension of Model that provides more flexibility and functionality, such as the ability to merge two models together.
@GetMapping("/printViewPage")
public String passParametersWithModelMap(ModelMap map) {
map.addAttribute("welcomeMessage", "welcome");
map.addAttribute("message", "Baeldung");
return "viewPage";
} ModelAndView is a wrapper that combines both a ModelMap and a view name or View object. This is useful when you need to pass multiple pieces of data to view, or if you need to specify a different view for different data.
@GetMapping("/goToViewPage")
public ModelAndView passParametersWithModelAndView() {
ModelAndView modelAndView = new ModelAndView("viewPage");
modelAndView.addObject("message", "Baeldung");
return modelAndView;
} In general, it is best to stick with using Model unless you need the extra functionality that ModelMap or ModelAndView provide. However, there is no harm in using any of these three methods - it is simply a matter of preference and what works best for your particular application.
There are two main types of architectures for Spring MVC applications: Model 1 and Model 2.
Depending on your needs, you may choose one or more architectures for your Spring MVC application. If you need a simple application that is quick to develop and deploy, Model 1 might be the best choice. If you need a more scalable and maintainable application, Model 2 is probably a better option. There are several benefits of using a Model 2 architecture.
Spring MVC is flexible enough to support both Model 1 and Model 2 architectures. You can even mix and match components from both architectures to create a hybrid approach that meets your specific needs.
The front controller of the Spring MVC framework is the DispatcherServlet. This servlet initializes the spring container, provides configuration options, and dispatches requests to controllers. The DispatcherServlet is responsible for resolving view names and forwarding requests to the appropriate View class. It also processes any exceptions that may be thrown by the controller or view.
In addition, the DispatcherServlet offers a range of features that allow developers to customize its behavior. For example, developers can specify the order in which controllers are invoked, add interceptors to process requests, and map request URLs to specific controllers. The flexibility of the DispatcherServlet makes it an essential component of the Spring MVC framework.
The @PathVariable annotation is a very useful tool for developers working in Spring MVC as it allows them to capture variables from the URL path and bind them to method parameters. By using the @PathVariable annotation, developers are able to determine both the type and name of each variable that needs to be passed along with the request URL. This versatile annotation lets developers use dynamic URLs and make their applications more flexible while still following RESTful conventions.
Moreover, with @PathVariable's ability to accept regex expressions as input, multiple segments of the same route with different parameters can still be matched without writing multiple controller methods. All in all, the @PathVariable annotation provides developers a convenient way to use dynamic URLs when building applications with Spring MVC.
A key component of the Spring Framework is its annotation-based configuration. This allows developers to easily configure their applications without having to write lengthy XML configuration files. @Component, @Controller, @Repository, and @Service are annotations used in spring framework. Each annotation has a specific purpose and is used in different situations.
In general, the Spring Framework annotations can be used in any situation where you need to indicate that a class is part of the Spring application. These annotations are not limited to any specific situation or use case. However, it is important to understand the purpose of each annotation so that you can use them correctly in your own applications.
Spring MVC Interceptor is a concept that can be best explained with the help of an example. Suppose we have a Spring MVC application that contains two methods - one for handling GET requests and other for handling POST requests. Now, suppose we want to add some security checks before allowing any request to access these methods. This is where interceptors come into picture.
A Spring MVC interceptor is a component that can intercept incoming requests and outgoing responses in a Spring MVC application. Interceptors can be used to pre-process requests, post-process responses, or perform general tasks that need to be done before or after request processing.
Interceptors can be chained together; each interceptor in the chain will have an opportunity to process the request or response before it is passed on to the next interceptor in the chain. They are also useful for performing tasks that need to be done before or after request processing, such as logging, authentication, and authorization.
Interceptors can also be used to access resources that are not normally accessible to controllers, such as the HttpServletRequest and HttpSession objects. They are invoked in the order they are configured. Each interceptor in the chain will have an opportunity to process the request or response before it is passed on to the next interceptor in the chain.
If an interceptor throws an exception, the request will be forwarded to the exception handler for that interceptor. If no exception handler is configured for that interceptor, the exception will be propagated up the interceptor chain.
Thus, interceptors provide a powerful and convenient mechanism for adding extra functionality to Spring MVC applications. They can be used for a wide range of tasks, such as security checks, performance monitoring, etc.
In Spring MVC, the "initBinder" method is used to initialize WebDataBinder objects. WebDataBinder is used to bind request parameters to controller methods. The initBinder method takes a WebDataBinder object and an HttpServletRequest object as arguments. The WebDataBinder is then used to bind the request parameters to the controller method.
For example, if you have a controller method that takes a Person object as an argument, you can use the initBinder method to bind the person's name and age request parameters to the Person object.
This is useful when you want to automatically populate form fields with data from a database or other source. It can also be used to pre-process request parameters before they are passed to the controller method.
The initBinder method is called before the controller method is invoked. It is important to note that the WebDataBinder object is only used for binding request parameters. It cannot be used to bind other objects such as model attributes.
To use the init binder annotation, you first need to create a custom editor class that extends the PropertyEditorSupport class and overrides the setAsText() method. This method will be called whenever the user enters data into a field that is mapped to the type specified in the editor class.
Once you have created the custom editor class, you can annotate a controller method with the @InitBinder annotation and specify the type that this method should handle. The init binder annotated method must have a single argument of type WebDataBinder. This object provides methods for registering custom editors.
When it comes to Spring MVC, knowing about the various scopes of Spring beans is an essential interview question to consider. A bean's scope refers to a bean's life-cycle and how long objects are retained for a given scope. Spring offers six different scopes for beans - singleton, prototype, request, session, application and websocket.
Singleton scope ensures that only one instance of a bean is created per application context and it will be reused again if referred. Prototype scope denotes that a new instance of the bean will be created each time it is requested while in request scope a single bean is created each time an HTTP request lands on the server with subsequent requests reusing the same instance; this applies only to web aware Spring ApplicationContexts.
Differently than the associated behaviors of the previous scopes session scope produces another instance of Bean class in web applications whenever an HTTP session event occurs while like request scope this too applies only when you're running in a web-aware Spring ApplicationContext.
On top of these there are also two other scopes worth considering which are application and websocket scopes: application increases the liveliness span so that bean exists for as long as your whole application does while websocket makes a long lived conversation possible between browser and server due to its relaxed restrictions on resource requests meaning that bean lives from the opening of WebSocket connection until its closure.
Inversion of Control (IoC) is a software development principle that is implemented using Dependency Injection (DI). It helps to decouple components, allowing for increased flexibility and maintainability in both newly developed and legacy code. An IoC container manages the lifecycle of the dependent objects, making sure that the various components work together. The benefits of IOC include an increase in testability; it allows developers to easily switch components or modify existing objects without having to rewrite code.
Additionally, with IoC multiple instances can be created off of predefined object templates. Finally, it allows developers to focus on project specific code instead of boilerplate code, helping them develop better applications faster by reducing maintenance time and speeding up deployments. By utilizing Inversion of Control, developers are able to design robust applications while taking advantage of all the benefits that come with employing IOC containers.