SlideShare une entreprise Scribd logo
1  sur  60
Télécharger pour lire hors ligne
Introducing Spring Framework
Who am I ?
Developing Software
“I’m not a great programmer, I’m just a good
programmer with great habits.”
                                      Kent Beck
Our toolbox


      • Clean code
      • TDD
      • Design patters
      • Frameworks
      • ...
Clean code
Source code are for humans not computers!




                               “Code Smells”, Martin Fowler
TDD
Design Patterns
Frameworks
Choose your weapon !
Spring Framework
The Spring Framework



• Best practices
• Proven Solutions
• OpenSource
• Continuously growing
Spring Ecosystem

                  Spring MVC            Spring
                                        WebFlow

 Spring Dynamic                                   Spring ROO
     Modules


                                                    Spring Web
Spring Security                                      Services
                                 Spring
                               Framework
                                                        Spring
 Spring Batch                                         Integration


                                                   Spring Data
   Spring Social

                       Spring Android      And many more...
In a Nutshell

• IoC container
• Lightweight
• Comprehensive coverage of AOP
• TDD
• Modular
Where?

• Junit system Test
• Java EE web application
• Java EE enterprise application
• Standalone Java application
What?
Spring Framework provides comprehensive
infrastructure support for developing Java
applications.
   −Spring   deals with the plumbing
   −So   you can focus on solving the domain problem.
And that means...

You can build applications from “plain old Java
objects” (POJOs) and to apply enterprise services
non-invasively to POJOs.
Spring IoC
Inversion of Control (IoC)

“Is a programming technique, in which object coupling
is bound at run time by an assembler object and is
typically not known at compile time using static
analysis.”
How?
Spring Triangle




                       As
                          p
                   n



                         ec
                io




                            t-O
              ct
            je




                               rie
          In




                               nt
           y
        nc




                                 ed
               Simple
     de




                                     Pr
      n




                                       og
   pe




               Object

                                         ra
De




                                           m
                                          m
                                           in
                                              g
 Enterprise Service Abstractions
Production
Unit Test




   Stub / Mock
Local development




            H2
Deployments


Development      Test           QA          Production




   or             +              +              +
 Mocks        Dummy data   Dump real data   Real data
Dependency Injection (IoC)


  • XML
  • Annotations
  • Java
TransferService
AccountRepository
XML




      app-config.xml
And run it !
Annotations
XML




      app-config.xml
And run it !
Java Configuration
                Defined outside !!
Spring AOP
Aspect-Oriented Programming

“AOP is a programming paradigm that aims to increase
modularity by allowing the separation of cross-cutting
concerns”
Cross-Cutting Concerns?
Generic funcionality that is needed in many
places in your application


   −   Security
   −   Caching
   −   Logging
   −   ...
Tangling




           Mixing of concerns
Scattering




             Duplication
How?

                       AOP




                                                           <<Interface>>
                                                          TransferService

TransferServiceImpl
      (Target)
                                                      Spring AOP Proxy

                                  transfer(300,1,2)

                                                        Aspect          Target
       ExceptionReporterAdvice
               (Aspect)
With Spring AOP


                                                                          TransferServiceImpl.java
                                                                           TransferServiceImpl.java




                                                                        ExceptionReporterAdvice.java
                                                                        ExceptionReporterAdvice.java

<beans>
  <aop:aspectj-autoproxy>
    <aop:include name=“exceptionReporter” />
  </aop:aspectj-autoproxy>

   <bean id=“exceptionReporter” class=“...ExceptionReporterAdvice” />
</beans>
                                                                               Spring-aop.xml
                                                                               Spring-aop.xml
What about ... ?
Web Access




HTTP / HTML
Spring Web Integration

• Spring provides support in the Web layer
  − Spring MVC, Spring WebFlow, …



• However, you are free to use Spring with any Java
web framework
  − Struts,Tapestry, JSF, WebWork, Wicket, ...
web.xml

<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>
     /WEB-INF/spring/app-config.xml
   </param-value>
</context-param>

<listener>
   <listener-class>
      org.springframework.web.context.ContextLoaderListener
   </listener-class>
</listener>
Spring MVC
Model - View - Controller
Spring MVC
                                                              @Controller
                                                             BlazeDS (Flex)
                                                                WebFlow
request                                                            ...
                                                                    HandlerMapping
                                                                     HandlerMapping
           DispatcherServlet                       Handler          HandlerAdapter
                                                                     HandlerAdapter

response                            model + View

                        render(model)
           JSP


                 View
                          JSP
                          PDF
                          Excel
                           ...
                                ViewResolver
                                 ViewResolver
Spring MVC
Quick Start

1. Deploy a Dispatcher Servlet
2. Implement a request Handler (Controller)
3. Implement the View
4. Register the Controller
5. Deploy and Test
Deploy Dispatcher Servlet
                                                                          web.xml
<servlet>
  <servlet-name>dispatcherServlet</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>
          /WEB-INF/spring/mvc-config.xml
     </param-value>
  </init-param>
</servlet>

<servlet-mapping>
  <servlet-name>dispatcherServlet</servlet-name>
  <url-pattern>/app/*</url-pattern>
</servlet-mapping>




                                                Don't forget ContextLoaderListener
                                                          (app-config.xml)
Implement Controller
Register Controller

<beans>

  <bean class=”org.spf.web...InternalResourceViewResolver”>
    <property name=”prefix” value=”/WEB-INF/views/” />
    <property name=”suffix” value=”.jsp” />
  </bean>

  <bean class=”com.extrema...TransferController” />

</beans>




                                                      /WEB-INF/spring/mvc-config.xml
Implement View
<html>
 <head><title>Your transfer</title></head>
 <body>
    <h1>Your transfer </h1>
    Id = ${transfer.id} <br/>
    Date = ${transfer.date} <br/>
    Amount = ${transfer.amount} <br/>
    Credit = ${transfer.credit} <br/>
    Debit = ${transfer.debit} <br/>
  </body>
</html>




                                             /WEB-INF/views/transfer.jsp
Deploy and Test
http://localhost:8080/app/transfer/1




    Your transfer
         Id = 1
         Date = 2013/01/01
         Amount = 300.0
         Credit = 1234
         Debit = 5678
… and much more
• Stateless converter for binding and formatting
• Support for JSR-303 declarative validation
• I18n
• Themes
• Content Negotiation
• Support for RESTful web services
• WebFlow
Summary
Conclusions

• Developing software is a craft.
• We need tools to help us in the process.
   −Good   practices
   −Frameworks

• It depends on you to choose the right one for your needs.
• Spring is just one of them.
Q&A
Ernesto Hernández
           @ehdez73

Contenu connexe

Tendances

Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and FriendsYun Zhi Lin
 
Using Apache Camel connectors for external connectivity
Using Apache Camel connectors for external connectivityUsing Apache Camel connectors for external connectivity
Using Apache Camel connectors for external connectivityClaus Ibsen
 
Mastering Grails 3 Plugins - Greach 2016
Mastering Grails 3 Plugins - Greach 2016Mastering Grails 3 Plugins - Greach 2016
Mastering Grails 3 Plugins - Greach 2016Alvaro Sanchez-Mariscal
 
My "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsMy "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsGR8Conf
 
Microservices with apache_camel_barcelona
Microservices with apache_camel_barcelonaMicroservices with apache_camel_barcelona
Microservices with apache_camel_barcelonaClaus Ibsen
 
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition! Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition! Michel Schudel
 
Lifthub (#rpscala 26)
Lifthub (#rpscala 26)Lifthub (#rpscala 26)
Lifthub (#rpscala 26)k4200
 
DevOps tools for everyone - Vagrant, Puppet and Webmin
DevOps tools for everyone - Vagrant, Puppet and WebminDevOps tools for everyone - Vagrant, Puppet and Webmin
DevOps tools for everyone - Vagrant, Puppet and Webminpostrational
 
Micronaut For Single Page Apps
Micronaut For Single Page AppsMicronaut For Single Page Apps
Micronaut For Single Page AppsZachary Klein
 
Apache Camel workshop at BarcelonaJUG in January 2014
Apache Camel workshop at BarcelonaJUG in January 2014Apache Camel workshop at BarcelonaJUG in January 2014
Apache Camel workshop at BarcelonaJUG in January 2014Claus Ibsen
 
Dropwizard Introduction
Dropwizard IntroductionDropwizard Introduction
Dropwizard IntroductionAnthony Chen
 
Building Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksBuilding Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksMike Hugo
 
markedj: The best of markdown processor on JVM
markedj: The best of markdown processor on JVMmarkedj: The best of markdown processor on JVM
markedj: The best of markdown processor on JVMtakezoe
 
Puppet Camp Paris 2015: Continuous Integration of Puppet Code (Intermediate)
Puppet Camp Paris 2015: Continuous Integration of Puppet Code (Intermediate) Puppet Camp Paris 2015: Continuous Integration of Puppet Code (Intermediate)
Puppet Camp Paris 2015: Continuous Integration of Puppet Code (Intermediate) Puppet
 
Spring Boot Revisited with KoFu and JaFu
Spring Boot Revisited with KoFu and JaFuSpring Boot Revisited with KoFu and JaFu
Spring Boot Revisited with KoFu and JaFuVMware Tanzu
 
Application Architectures in Grails
Application Architectures in GrailsApplication Architectures in Grails
Application Architectures in GrailsPeter Ledbrook
 
Sling IDE Tooling @ adaptTo 2013
Sling IDE Tooling @ adaptTo 2013Sling IDE Tooling @ adaptTo 2013
Sling IDE Tooling @ adaptTo 2013Robert Munteanu
 

Tendances (20)

Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and Friends
 
Using Apache Camel connectors for external connectivity
Using Apache Camel connectors for external connectivityUsing Apache Camel connectors for external connectivity
Using Apache Camel connectors for external connectivity
 
Mastering Grails 3 Plugins - Greach 2016
Mastering Grails 3 Plugins - Greach 2016Mastering Grails 3 Plugins - Greach 2016
Mastering Grails 3 Plugins - Greach 2016
 
My "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsMy "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails Projects
 
Microservices with apache_camel_barcelona
Microservices with apache_camel_barcelonaMicroservices with apache_camel_barcelona
Microservices with apache_camel_barcelona
 
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition! Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
 
Lifthub (#rpscala 26)
Lifthub (#rpscala 26)Lifthub (#rpscala 26)
Lifthub (#rpscala 26)
 
DevOps tools for everyone - Vagrant, Puppet and Webmin
DevOps tools for everyone - Vagrant, Puppet and WebminDevOps tools for everyone - Vagrant, Puppet and Webmin
DevOps tools for everyone - Vagrant, Puppet and Webmin
 
GlassFish Embedded API
GlassFish Embedded APIGlassFish Embedded API
GlassFish Embedded API
 
Micronaut For Single Page Apps
Micronaut For Single Page AppsMicronaut For Single Page Apps
Micronaut For Single Page Apps
 
Apache Camel workshop at BarcelonaJUG in January 2014
Apache Camel workshop at BarcelonaJUG in January 2014Apache Camel workshop at BarcelonaJUG in January 2014
Apache Camel workshop at BarcelonaJUG in January 2014
 
Spring webflux
Spring webfluxSpring webflux
Spring webflux
 
Dropwizard Introduction
Dropwizard IntroductionDropwizard Introduction
Dropwizard Introduction
 
Building Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksBuilding Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And Tricks
 
markedj: The best of markdown processor on JVM
markedj: The best of markdown processor on JVMmarkedj: The best of markdown processor on JVM
markedj: The best of markdown processor on JVM
 
Puppet Camp Paris 2015: Continuous Integration of Puppet Code (Intermediate)
Puppet Camp Paris 2015: Continuous Integration of Puppet Code (Intermediate) Puppet Camp Paris 2015: Continuous Integration of Puppet Code (Intermediate)
Puppet Camp Paris 2015: Continuous Integration of Puppet Code (Intermediate)
 
Angular beans
Angular beansAngular beans
Angular beans
 
Spring Boot Revisited with KoFu and JaFu
Spring Boot Revisited with KoFu and JaFuSpring Boot Revisited with KoFu and JaFu
Spring Boot Revisited with KoFu and JaFu
 
Application Architectures in Grails
Application Architectures in GrailsApplication Architectures in Grails
Application Architectures in Grails
 
Sling IDE Tooling @ adaptTo 2013
Sling IDE Tooling @ adaptTo 2013Sling IDE Tooling @ adaptTo 2013
Sling IDE Tooling @ adaptTo 2013
 

En vedette (9)

Microservicios, en qué lío me he metido
Microservicios, en qué lío me he metidoMicroservicios, en qué lío me he metido
Microservicios, en qué lío me he metido
 
Twilio using Groovy Grails
Twilio using Groovy GrailsTwilio using Groovy Grails
Twilio using Groovy Grails
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with Groovy
 
Transaction isolation levels
Transaction isolation levelsTransaction isolation levels
Transaction isolation levels
 
Grails Custom Tag lib
Grails Custom Tag libGrails Custom Tag lib
Grails Custom Tag lib
 
Microservicios, en qué lío me he metido
Microservicios, en qué lío me he metidoMicroservicios, en qué lío me he metido
Microservicios, en qué lío me he metido
 
Arquitecturas de microservicios - Codemotion 2014
Arquitecturas de microservicios  -  Codemotion 2014Arquitecturas de microservicios  -  Codemotion 2014
Arquitecturas de microservicios - Codemotion 2014
 
Arquitecturas de microservicios - @cibbva
Arquitecturas de microservicios - @cibbvaArquitecturas de microservicios - @cibbva
Arquitecturas de microservicios - @cibbva
 
Implementando una Arquitectura de Microservicios
Implementando una Arquitectura de MicroserviciosImplementando una Arquitectura de Microservicios
Implementando una Arquitectura de Microservicios
 

Similaire à Introducing spring

04.egovFrame Runtime Environment Workshop
04.egovFrame Runtime Environment Workshop04.egovFrame Runtime Environment Workshop
04.egovFrame Runtime Environment WorkshopChuong Nguyen
 
NIG 系統開發指引
NIG 系統開發指引NIG 系統開發指引
NIG 系統開發指引Guo Albert
 
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)Daniel Bryant
 
Spring MVC introduction HVA
Spring MVC introduction HVASpring MVC introduction HVA
Spring MVC introduction HVAPeter Maas
 
ASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web developmentASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web developmentVolodymyr Voytyshyn
 
Spring 3 MVC CodeMash 2009
Spring 3 MVC   CodeMash 2009Spring 3 MVC   CodeMash 2009
Spring 3 MVC CodeMash 2009kensipe
 
MongoDB for Java Devs with Spring Data - MongoPhilly 2011
MongoDB for Java Devs with Spring Data - MongoPhilly 2011MongoDB for Java Devs with Spring Data - MongoPhilly 2011
MongoDB for Java Devs with Spring Data - MongoPhilly 2011MongoDB
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - CoreDzmitry Naskou
 
Spring 3 - Der dritte Frühling
Spring 3 - Der dritte FrühlingSpring 3 - Der dritte Frühling
Spring 3 - Der dritte FrühlingThorsten Kamann
 
Enterprise Spring Building Scalable Applications
Enterprise Spring Building Scalable ApplicationsEnterprise Spring Building Scalable Applications
Enterprise Spring Building Scalable ApplicationsGordon Dickens
 
MongoDB for Java Developers with Spring Data
MongoDB for Java Developers with Spring DataMongoDB for Java Developers with Spring Data
MongoDB for Java Developers with Spring DataChris Richardson
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applicationshchen1
 
Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Codemotion
 
Introduction to Spring sec1.pptx
Introduction to Spring sec1.pptxIntroduction to Spring sec1.pptx
Introduction to Spring sec1.pptxNourhanTarek23
 
TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011bobmcwhirter
 
NIG系統報表開發指南
NIG系統報表開發指南NIG系統報表開發指南
NIG系統報表開發指南Guo Albert
 
Spring Framework
Spring FrameworkSpring Framework
Spring Frameworknomykk
 

Similaire à Introducing spring (20)

04.egovFrame Runtime Environment Workshop
04.egovFrame Runtime Environment Workshop04.egovFrame Runtime Environment Workshop
04.egovFrame Runtime Environment Workshop
 
NIG 系統開發指引
NIG 系統開發指引NIG 系統開發指引
NIG 系統開發指引
 
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
 
Spring MVC introduction HVA
Spring MVC introduction HVASpring MVC introduction HVA
Spring MVC introduction HVA
 
ASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web developmentASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web development
 
Spring 3 MVC CodeMash 2009
Spring 3 MVC   CodeMash 2009Spring 3 MVC   CodeMash 2009
Spring 3 MVC CodeMash 2009
 
MongoDB for Java Devs with Spring Data - MongoPhilly 2011
MongoDB for Java Devs with Spring Data - MongoPhilly 2011MongoDB for Java Devs with Spring Data - MongoPhilly 2011
MongoDB for Java Devs with Spring Data - MongoPhilly 2011
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Jsf Framework
Jsf FrameworkJsf Framework
Jsf Framework
 
Spring Mvc
Spring MvcSpring Mvc
Spring Mvc
 
Spring 3 - Der dritte Frühling
Spring 3 - Der dritte FrühlingSpring 3 - Der dritte Frühling
Spring 3 - Der dritte Frühling
 
Enterprise Spring Building Scalable Applications
Enterprise Spring Building Scalable ApplicationsEnterprise Spring Building Scalable Applications
Enterprise Spring Building Scalable Applications
 
MongoDB for Java Developers with Spring Data
MongoDB for Java Developers with Spring DataMongoDB for Java Developers with Spring Data
MongoDB for Java Developers with Spring Data
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...
 
Introduction to Spring sec1.pptx
Introduction to Spring sec1.pptxIntroduction to Spring sec1.pptx
Introduction to Spring sec1.pptx
 
TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011
 
NIG系統報表開發指南
NIG系統報表開發指南NIG系統報表開發指南
NIG系統報表開發指南
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Spring
SpringSpring
Spring
 

Introducing spring

  • 4. “I’m not a great programmer, I’m just a good programmer with great habits.” Kent Beck
  • 5. Our toolbox • Clean code • TDD • Design patters • Frameworks • ...
  • 6. Clean code Source code are for humans not computers! “Code Smells”, Martin Fowler
  • 7. TDD
  • 12. The Spring Framework • Best practices • Proven Solutions • OpenSource • Continuously growing
  • 13. Spring Ecosystem Spring MVC Spring WebFlow Spring Dynamic Spring ROO Modules Spring Web Spring Security Services Spring Framework Spring Spring Batch Integration Spring Data Spring Social Spring Android And many more...
  • 14. In a Nutshell • IoC container • Lightweight • Comprehensive coverage of AOP • TDD • Modular
  • 15. Where? • Junit system Test • Java EE web application • Java EE enterprise application • Standalone Java application
  • 16. What? Spring Framework provides comprehensive infrastructure support for developing Java applications. −Spring deals with the plumbing −So you can focus on solving the domain problem.
  • 17. And that means... You can build applications from “plain old Java objects” (POJOs) and to apply enterprise services non-invasively to POJOs.
  • 19. Inversion of Control (IoC) “Is a programming technique, in which object coupling is bound at run time by an assembler object and is typically not known at compile time using static analysis.”
  • 20. How?
  • 21. Spring Triangle As p n ec io t-O ct je rie In nt y nc ed Simple de Pr n og pe Object ra De m m in g Enterprise Service Abstractions
  • 23. Unit Test Stub / Mock
  • 25. Deployments Development Test QA Production or + + + Mocks Dummy data Dump real data Real data
  • 26. Dependency Injection (IoC) • XML • Annotations • Java
  • 29. XML app-config.xml
  • 32. XML app-config.xml
  • 34. Java Configuration Defined outside !!
  • 36. Aspect-Oriented Programming “AOP is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns”
  • 37. Cross-Cutting Concerns? Generic funcionality that is needed in many places in your application − Security − Caching − Logging − ...
  • 38. Tangling Mixing of concerns
  • 39. Scattering Duplication
  • 40. How? AOP <<Interface>> TransferService TransferServiceImpl (Target) Spring AOP Proxy transfer(300,1,2) Aspect Target ExceptionReporterAdvice (Aspect)
  • 41. With Spring AOP TransferServiceImpl.java TransferServiceImpl.java ExceptionReporterAdvice.java ExceptionReporterAdvice.java <beans> <aop:aspectj-autoproxy> <aop:include name=“exceptionReporter” /> </aop:aspectj-autoproxy> <bean id=“exceptionReporter” class=“...ExceptionReporterAdvice” /> </beans> Spring-aop.xml Spring-aop.xml
  • 44. Spring Web Integration • Spring provides support in the Web layer − Spring MVC, Spring WebFlow, … • However, you are free to use Spring with any Java web framework − Struts,Tapestry, JSF, WebWork, Wicket, ...
  • 45. web.xml <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring/app-config.xml </param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener>
  • 47. Model - View - Controller
  • 48. Spring MVC @Controller BlazeDS (Flex) WebFlow request ... HandlerMapping HandlerMapping DispatcherServlet Handler HandlerAdapter HandlerAdapter response model + View render(model) JSP View JSP PDF Excel ... ViewResolver ViewResolver
  • 50. Quick Start 1. Deploy a Dispatcher Servlet 2. Implement a request Handler (Controller) 3. Implement the View 4. Register the Controller 5. Deploy and Test
  • 51. Deploy Dispatcher Servlet web.xml <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring/mvc-config.xml </param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dispatcherServlet</servlet-name> <url-pattern>/app/*</url-pattern> </servlet-mapping> Don't forget ContextLoaderListener (app-config.xml)
  • 53. Register Controller <beans> <bean class=”org.spf.web...InternalResourceViewResolver”> <property name=”prefix” value=”/WEB-INF/views/” /> <property name=”suffix” value=”.jsp” /> </bean> <bean class=”com.extrema...TransferController” /> </beans> /WEB-INF/spring/mvc-config.xml
  • 54. Implement View <html> <head><title>Your transfer</title></head> <body> <h1>Your transfer </h1> Id = ${transfer.id} <br/> Date = ${transfer.date} <br/> Amount = ${transfer.amount} <br/> Credit = ${transfer.credit} <br/> Debit = ${transfer.debit} <br/> </body> </html> /WEB-INF/views/transfer.jsp
  • 55. Deploy and Test http://localhost:8080/app/transfer/1 Your transfer Id = 1 Date = 2013/01/01 Amount = 300.0 Credit = 1234 Debit = 5678
  • 56. … and much more • Stateless converter for binding and formatting • Support for JSR-303 declarative validation • I18n • Themes • Content Negotiation • Support for RESTful web services • WebFlow
  • 58. Conclusions • Developing software is a craft. • We need tools to help us in the process. −Good practices −Frameworks • It depends on you to choose the right one for your needs. • Spring is just one of them.
  • 59. Q&A
  • 60. Ernesto Hernández @ehdez73