SlideShare a Scribd company logo
Spring Framework 3.0 MVC
       Aaron Schram
Me
University of Colorado PhD Student
  Software Engineering
Previously employment
  Mocapay, Inc (mobile payments)
  Rally Software (agile tooling)
  BEA (Weblogic Portal)
  Lockheed Martin
What's 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




   Uses the Front Controller Design Pattern
Defining The Dispatcher Servlet




Defining a Dispatcher Servlet named "spring" that will intercept all
                   urls to this web application
Spring Configuration
 By default Spring looks for a servletname -
 servlet.xml file in /WEB-INF
 For the previous example we would need to
 create a file in /WEB-INF named spring-servlet.
 xml
spring-servlet.xml
spring-servlet.xml cont.




<mvc:annotation-driven /> tells Spring to support annotations like
 @Controller, @RequestMapping and others that simplify the
            writing and configuration of controllers
spring-servlet.xml cont.




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.




   Tell Spring where to automatically detect controllers
Configuration Done!
      Woo Hoo!
So What's a Controller Look Like?
Example: Classroom Controller




 A Controller that gets a class or all the students in the class
Mark this class as a controller
Define what default URLs this class should respond to
Side Note: Autowiring




 Autowiring allows Spring to do the instantiation of the class you
want to make use of for you. At run time you will be able to access
 all methods of the class without worrying about how you got the
         class. This is known as Dependency Injection.
Back To Classroom Example




This method is the default method called when /classroom or / is
hit from a client. It simply forwards to a jsp named classroom.jsp
                        located in /WEB-INF/jsp
Side Note: Restful URLs

 Spring like many other popular frameworks can make use of
 RESTful URLs
     They come in the style of /users/user_id
     Commonly without any extension such as .html
 Popularized by Ruby on Rails
  Collections are accessed like:
     /users
 Individual entries are accessed like:
     /users/user_id
 CRUD operations are done via HTTP methods
     PUT, POST, GET, DELETE
Classroom RESTful URLs




The highlighted section above demonstrates how to accomplish
   RESTful URLs in the Spring MVC Framework. Using the
@PathVariable annotation you can gain access to the variable
  passed in on the URI. This is commonly referred to as URI
                          Templating.
What's a Model?

 A Model is used in Spring MVC to pass
 objects from the controller tier up into the view
 A Model is really just a java.util.Map
 You can add attributes to a Model and they
 will be put on the request as attributes and
 available in the applications PageContext .
 In Spring you can simply pass back a Map or
 one of two Spring specific classes; ModelMap
 or Model
ModelMap Example




 In the above example we use a service method to read and return
a Classroom object. We make that Classroom object available to
the view under the key "classroom " by calling addAttribute() on
                         the ModelMap
Getting All Students In A Classroom




   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
Aaron Schram
aaron.schram@colorado.edu

More Related Content

What's hot

Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
Dzmitry Naskou
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
Jonathan Holloway
 
Spring Core
Spring CoreSpring Core
Spring Core
Pushan Bhattacharya
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
Vinay Kumar
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
Josué Neis
 
Spring jdbc
Spring jdbcSpring jdbc
Spring jdbc
Harshit Choudhary
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Serhat Can
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
nomykk
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!Jakub Kubrynski
 
Spring User Guide
Spring User GuideSpring User Guide
Spring User Guide
Muthuselvam RS
 
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slidesSpring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Hitesh-Java
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
NexThoughts Technologies
 
Spring Boot
Spring BootSpring Boot
Spring Boot
Jaran Flaath
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
Rasheed Waraich
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
07.pallav
 
Introduction to thymeleaf
Introduction to thymeleafIntroduction to thymeleaf
Introduction to thymeleaf
NexThoughts Technologies
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
Naphachara Rattanawilai
 

What's hot (20)

Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
Spring jdbc
Spring jdbcSpring jdbc
Spring jdbc
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
 
Spring annotation
Spring annotationSpring annotation
Spring annotation
 
Spring User Guide
Spring User GuideSpring User Guide
Spring User Guide
 
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slidesSpring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Spring framework core
Spring framework coreSpring framework core
Spring framework core
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Introduction to thymeleaf
Introduction to thymeleafIntroduction to thymeleaf
Introduction to thymeleaf
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 

Viewers also liked

Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC framework
Mohit Gupta
 
Spring MVC Basics
Spring MVC BasicsSpring MVC Basics
Spring MVC Basics
Bozhidar Bozhanov
 
Spring bean mod02
Spring bean mod02Spring bean mod02
Spring bean mod02Guo Albert
 
Spring 3 MVC CodeMash 2009
Spring 3 MVC   CodeMash 2009Spring 3 MVC   CodeMash 2009
Spring 3 MVC CodeMash 2009
kensipe
 
Spring Framework - Validation
Spring Framework - ValidationSpring Framework - Validation
Spring Framework - Validation
Dzmitry Naskou
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
Emprovise
 
Presentation Spring, Spring MVC
Presentation Spring, Spring MVCPresentation Spring, Spring MVC
Presentation Spring, Spring MVCNathaniel Richand
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
Abdelhakim Bachar
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
Roman Pichlík
 
the Spring 4 update
the Spring 4 updatethe Spring 4 update
the Spring 4 update
Joshua Long
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVCGuy Nir
 
Spring 4 Web App
Spring 4 Web AppSpring 4 Web App
Spring 4 Web App
Rossen Stoyanchev
 
Next stop: Spring 4
Next stop: Spring 4Next stop: Spring 4
Next stop: Spring 4
Oleg Tsal-Tsalko
 
Spring MVC Annotations
Spring MVC AnnotationsSpring MVC Annotations
Spring MVC Annotations
Jordan Silva
 
Spring MVC 4.2: New and Noteworthy
Spring MVC 4.2: New and NoteworthySpring MVC 4.2: New and Noteworthy
Spring MVC 4.2: New and Noteworthy
Rossen Stoyanchev
 
Resource Handling in Spring MVC 4.1
Resource Handling in Spring MVC 4.1Resource Handling in Spring MVC 4.1
Resource Handling in Spring MVC 4.1
Rossen Stoyanchev
 
Support de cours Spring M.youssfi
Support de cours Spring  M.youssfiSupport de cours Spring  M.youssfi
Support de cours Spring M.youssfi
ENSET, Université Hassan II Casablanca
 

Viewers also liked (19)

Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC framework
 
Spring MVC Basics
Spring MVC BasicsSpring MVC Basics
Spring MVC Basics
 
Spring bean mod02
Spring bean mod02Spring bean mod02
Spring bean mod02
 
Spring 3 MVC CodeMash 2009
Spring 3 MVC   CodeMash 2009Spring 3 MVC   CodeMash 2009
Spring 3 MVC CodeMash 2009
 
Spring Framework - Validation
Spring Framework - ValidationSpring Framework - Validation
Spring Framework - Validation
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Presentation Spring, Spring MVC
Presentation Spring, Spring MVCPresentation Spring, Spring MVC
Presentation Spring, Spring MVC
 
Get ready for spring 4
Get ready for spring 4Get ready for spring 4
Get ready for spring 4
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
the Spring 4 update
the Spring 4 updatethe Spring 4 update
the Spring 4 update
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVC
 
Spring 4 Web App
Spring 4 Web AppSpring 4 Web App
Spring 4 Web App
 
Next stop: Spring 4
Next stop: Spring 4Next stop: Spring 4
Next stop: Spring 4
 
Spring MVC Annotations
Spring MVC AnnotationsSpring MVC Annotations
Spring MVC Annotations
 
Spring MVC 4.2: New and Noteworthy
Spring MVC 4.2: New and NoteworthySpring MVC 4.2: New and Noteworthy
Spring MVC 4.2: New and Noteworthy
 
JSF2 par la pratique
JSF2 par la pratiqueJSF2 par la pratique
JSF2 par la pratique
 
Resource Handling in Spring MVC 4.1
Resource Handling in Spring MVC 4.1Resource Handling in Spring MVC 4.1
Resource Handling in Spring MVC 4.1
 
Support de cours Spring M.youssfi
Support de cours Spring  M.youssfiSupport de cours Spring  M.youssfi
Support de cours Spring M.youssfi
 

Similar to Spring MVC

Spring MVC framework features and concepts
Spring MVC framework features and conceptsSpring MVC framework features and concepts
Spring MVC framework features and concepts
AsmaShaikh478737
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
Tuna Tore
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892Tuna Tore
 
Spring mvc 2.0
Spring mvc 2.0Spring mvc 2.0
Spring mvc 2.0
Rudra Garnaik, PMI-ACP®
 
Struts & spring framework issues
Struts & spring framework issuesStruts & spring framework issues
Struts & spring framework issues
Prashant Seth
 
quickguide-einnovator-7-spring-mvc
quickguide-einnovator-7-spring-mvcquickguide-einnovator-7-spring-mvc
quickguide-einnovator-7-spring-mvcjorgesimao71
 
Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2
Mindsmapped Consulting
 
Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2
javatrainingonline
 
Month 2 report
Month 2 reportMonth 2 report
Month 2 report
PRIYANKA FNU
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To Mvc
Volkan Uzun
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVC
John Lewis
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
Obinna Akunne
 
IRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHPIRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHP
IRJET Journal
 
Sprint Portlet MVC Seminar
Sprint Portlet MVC SeminarSprint Portlet MVC Seminar
Sprint Portlet MVC Seminar
John Lewis
 
ASPNet MVC series for beginers part 1
ASPNet MVC series for beginers part 1ASPNet MVC series for beginers part 1
ASPNet MVC series for beginers part 1Gaurav Arora
 
Asp net mvc series for beginers part 1
Asp net mvc series for beginers part 1Asp net mvc series for beginers part 1
Asp net mvc series for beginers part 1
Gaurav Arora
 

Similar to Spring MVC (20)

Spring MVC framework features and concepts
Spring MVC framework features and conceptsSpring MVC framework features and concepts
Spring MVC framework features and concepts
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
 
Spring mvc 2.0
Spring mvc 2.0Spring mvc 2.0
Spring mvc 2.0
 
Struts & spring framework issues
Struts & spring framework issuesStruts & spring framework issues
Struts & spring framework issues
 
quickguide-einnovator-7-spring-mvc
quickguide-einnovator-7-spring-mvcquickguide-einnovator-7-spring-mvc
quickguide-einnovator-7-spring-mvc
 
Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2
 
Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2
 
Month 2 report
Month 2 reportMonth 2 report
Month 2 report
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To Mvc
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVC
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
 
Mvc
MvcMvc
Mvc
 
Session 1
Session 1Session 1
Session 1
 
Jinal desai .net
Jinal desai .netJinal desai .net
Jinal desai .net
 
MVC
MVCMVC
MVC
 
IRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHPIRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHP
 
Sprint Portlet MVC Seminar
Sprint Portlet MVC SeminarSprint Portlet MVC Seminar
Sprint Portlet MVC Seminar
 
ASPNet MVC series for beginers part 1
ASPNet MVC series for beginers part 1ASPNet MVC series for beginers part 1
ASPNet MVC series for beginers part 1
 
Asp net mvc series for beginers part 1
Asp net mvc series for beginers part 1Asp net mvc series for beginers part 1
Asp net mvc series for beginers part 1
 

Recently uploaded

De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 

Recently uploaded (20)

De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 

Spring MVC

  • 1. Spring Framework 3.0 MVC Aaron Schram
  • 2. Me University of Colorado PhD Student Software Engineering Previously employment Mocapay, Inc (mobile payments) Rally Software (agile tooling) BEA (Weblogic Portal) Lockheed Martin
  • 3. What's 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
  • 4. 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.
  • 5. 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
  • 7. 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
  • 8. Dispatcher Servlet Architecture Uses the Front Controller Design Pattern
  • 9. Defining The Dispatcher Servlet Defining a Dispatcher Servlet named "spring" that will intercept all urls to this web application
  • 10. Spring Configuration By default Spring looks for a servletname - servlet.xml file in /WEB-INF For the previous example we would need to create a file in /WEB-INF named spring-servlet. xml
  • 12. spring-servlet.xml cont. <mvc:annotation-driven /> tells Spring to support annotations like @Controller, @RequestMapping and others that simplify the writing and configuration of controllers
  • 13. spring-servlet.xml cont. Define a simple view resolver that looks for JSPs that match a given view name in the director /WEB-INF/jsp
  • 14. spring-servlet.xml cont. Tell Spring where to automatically detect controllers
  • 16. So What's a Controller Look Like?
  • 17. Example: Classroom Controller A Controller that gets a class or all the students in the class
  • 18. Mark this class as a controller
  • 19. Define what default URLs this class should respond to
  • 20. Side Note: Autowiring Autowiring allows Spring to do the instantiation of the class you want to make use of for you. At run time you will be able to access all methods of the class without worrying about how you got the class. This is known as Dependency Injection.
  • 21. Back To Classroom Example This method is the default method called when /classroom or / is hit from a client. It simply forwards to a jsp named classroom.jsp located in /WEB-INF/jsp
  • 22. Side Note: Restful URLs Spring like many other popular frameworks can make use of RESTful URLs They come in the style of /users/user_id Commonly without any extension such as .html Popularized by Ruby on Rails Collections are accessed like: /users Individual entries are accessed like: /users/user_id CRUD operations are done via HTTP methods PUT, POST, GET, DELETE
  • 23. Classroom RESTful URLs The highlighted section above demonstrates how to accomplish RESTful URLs in the Spring MVC Framework. Using the @PathVariable annotation you can gain access to the variable passed in on the URI. This is commonly referred to as URI Templating.
  • 24. What's a Model? A Model is used in Spring MVC to pass objects from the controller tier up into the view A Model is really just a java.util.Map You can add attributes to a Model and they will be put on the request as attributes and available in the applications PageContext . In Spring you can simply pass back a Map or one of two Spring specific classes; ModelMap or Model
  • 25. ModelMap Example In the above example we use a service method to read and return a Classroom object. We make that Classroom object available to the view under the key "classroom " by calling addAttribute() on the ModelMap
  • 26. Getting All Students In A Classroom 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
  • 27. More Helpful Information SpringSource.org Chapter 15 RESTful URLs