Spring MVC
Spring MVC
Spring MVC
0 MVC
Spring MVC?
A model-view-controller framework for Java
web application
Made to simplify the writing and testing of
Java web applications
Fully integrates with the Spring dependency
injection (Inversion of Control) framework
Open Source
Developed and maintained by Interface21,
recently purchased by VMWare
Project Goals
J2EE should be easier to use
It is best to program to interfaces, rather than
classes. Spring reduces the complexity cost of using
interfaces to zero.
JavaBeans offer a great way of configuring
applications.
OO design is more important than any
implementation technology, such as J2EE.
Checked exceptions are overused in Java. A platform
shouldn't force you to catch exceptions you're
unlikely to be able to recover from.
Testability is essential, and a platform such as Spring
should help make your code easier to test.
Why Use Spring MVC?
For most purposes you only have to define one
Servlet in web.xml
Capable of Convention over Configuration
Similar to Ruby on Rails or other popular web
frameworks that work with dynamic languages
Normal business objects can be used to back forms
No need to duplicate objects just to implement an
MVC's command object interface
Very flexible view resolvers
Can by used to map *.json, *.xml, *.atom, etc to
the same logic code in one controller and simply
output the type of data requested
Enforces good Software Engineering principles like
SRP and DRY
Let's Get Started!
Dispatcher Servlet
Used to handle all incoming requests and route
them through Spring
Uses customizable logic to determine which
controllers should handle which requests
Forwards all responses to through view handlers
to determine the correct views to route responses
to
Exposes all beans defined in Spring to controllers
for dependency injection
Dispatcher Servlet Architecture
Define a simple view resolver that looks for JSPs that match a given
view name in the director /WEB-INF/jsp
spring-servlet.xml cont.
Above you can see that how to get all the students in a given
classroom by requesting the URL /classroom/{id} /students. A
Java List<Student> will be available to the classroom.jsp view for
display
More Helpful Information
SpringSource.org Chapter 15
RESTful URLs