Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Web frameworks, Spring MVC and Spring Boot

Michael Isvy
November 27, 2014

Web frameworks, Spring MVC and Spring Boot

Presentation from Paul Chapman and Michael Isvy at the Korea Spring User Group

Michael Isvy

November 27, 2014
Tweet

More Decks by Michael Isvy

Other Decks in Technology

Transcript

  1. 1
    Before we start
    Ÿ  ࠄ ೯ࢎী খࢲ ৈ۞࠙੄ झ݃౟ ಪਵ۽
    http://tinyurl.com/koreaspring ۽ ੉زೞ࣊ࢲ 5 ޙ೦ী ׹߸
    ࠗఌ ٘݀פ׮. (৘࢚ ࣗਃदр 1࠙)
    Ÿ  Please go to http://tinyurl.com/koreaspring on your mobile
    phone. Please answer those 5 questions (it takes one
    minute)

    View full-size slide

  2. 2
    •  전자정부 표준프레임워크 개발자 양성과정
    ü  일정 : 2014.03.10 ~ 2014.05.23 (400시간, 14명)
    ü  커리큘럼 : Java, Spring Framework, DBMS, Mini Project
    •  Java Application 전문가 양성 과정
    ü  일정 : (1차) 2014.06.30 ~ 2014.09.24 (400시간, 30명)
    (2차) 2014.08.07 ~ 2014.10.31 (400시간, 30명)
    ü  커리큘럼 : Java, Spring Framework, DBMS, Mini Project
    Hadoop, Big Data
    Java Programming
    3 weeks
    Spring Framework
    4 weeks
    Spring
    Project
    Big Data
    3 weeks
    -  Java Programming
    - JSP
    -  Core Spring
    -  Spring Web
    -  Hibernate w/ Spring
    -  Hadoop
    -  Data Science

    View full-size slide

  3. 3
    Paul  Chapman    Michael  Isvy        
     
    Ÿ  Pivotal Education
    2008
    - Spring
    - Tomcat
    2009-2012
    -  Spring
    -  Tomcat
    -  Cloud Foundry
    -  GemFire…
    2013 onwards
    -  Spring, Cloud Foundry
    -  Tomcat, Redis, Hadoop
    -  GemFire
    P

    View full-size slide

  4. 4
    Hadoop
    / Pivotal HD
    GemFire
    /SqlFire
    Apache Tomcat
    P

    View full-size slide

  5. 5
    Web frameworks in Java
    mvc
    M

    View full-size slide

  6. 6
    Disclaimer: framework versus standard
    Ÿ  JSF is part of Java EE specification
    Ÿ  Technically JSF is not exactly a web framework but rather a
    specification and an implementation
    –  We’ve used the word “framework” here to keep things simple
    P

    View full-size slide

  7. 7
    2000: Servlet/JSP
    public class MyServlet extends HttpServlet {"
    "
    "
    public void doGet(HttpServletRequest req, HttpServletResponse resp) {"
    …"
    }
    public void doPost(HttpServletRequest req, HttpServletResponse resp) {"

    }
    "
    }
    Not a POJO
    Request params
    parsed manually
    Form validation done
    manually
    No I18N support

    Verbose XML config
    M

    View full-size slide

  8. 8
    2003: Apache Struts
    public class UserAction extends Action {"
    "
    "
    public void execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest req, HttpServletResponse resp) {"
    …"
    }
    "
    }
    Not a POJO
    Request params
    parsed manually
    Form validation done
    manually
    Verbose XML config

    public class UserForm extends ActionForm {"
    "
    private String name;
    public String getName() { return name; }
    public void seName(String name) { this.name = name; }"
    }
    No Internationalization support
    P

    View full-size slide

  9. 9
    2003: Apache Struts
    Ÿ  Java community formed a consensus
    Ÿ  Quickly became the way to go for Java web frameworks
    Ÿ  So what happened next?
    9
    P

    View full-size slide

  10. 10
    2004: JSF
    Ÿ  Struts was created by Craig McClanahan
    –  Also one of the key founders of Servlet, JSP, JSTL and Tomcat
    Ÿ  Craig wanted to create a component-oriented Web
    framework
    –  Event/Listener model
    M

    View full-size slide

  11. 11
    2004: JSF
    Ÿ  Problem: view layer was good but some major limitations
    –  Form validation very limited
    –  Couldn’t disable JavaScript
    –  No support for “GET” methods…
    Ÿ  Specification versus framework
    –  For it to succeed, JSF should have been a framework, not a
    specification
    ▪  Frameworks can be updated every month
    ▪  Java EE Specs are updated once every 2 years
    M

    View full-size slide

  12. 12
    2005: The JSF / Struts 1 & 2 story
    Original plan What happened
    Struts JSF
    Struts 2
    Struts WebWork
    Struts 2
    M

    View full-size slide

  13. 13
    2005: Spring MVC without annotations
    Ÿ  Spring MVC was similar to Struts
    –  But more modern
    ▪  Easier to extend
    ▪  Well integrated for Dependency Injection
    public class UserController
    extends SimpleFormController {

    private UserService service;
    public ModelAndView
    onSubmit(Object command)
    { //... }
    }
    P
    Not a POJO
    Request params
    parsed manually
    Form validation done
    manually
    Simpler XML config

    No Internationalization support

    View full-size slide

  14. 14
    2008: Spring @MVC
    Ÿ  Annotations are the way to go for Spring @MVC!
    public class UserController
    extends SimpleFormController {

    private UserService service;
    public ModelAndView
    onSubmit(Object command)
    { //... }
    }
    @Controller
    public class UserController {
    @Autowired
    private UserService service;
    @RequestMapping(value="/users/",
    method=RequestMethod.POST)
    public ModelAndView createUser(User user) 

    { //... }
    }
    P
    Now POJO based!!
    No XML needed for controllers anymore!!

    View full-size slide

  15. 15
    Popularity of Java Web frameworks in 2014
    http://pages.zeroturnaround.com/RebelLabs-AllReportLanders_TheCuriousCodersGuidetoJavaWebFrameworks.html
    P

    View full-size slide

  16. 16
    Let’s talk about CSS and Javascript
    Ÿ  Back in 2008, there were plenty of small CSS frameworks
    –  None of them really did the job
    Ÿ  Now there is Bootstrap!
    M

    View full-size slide

  17. 17
    What is Bootstrap?
    Ÿ  Originally called “Twitter Bootstrap”
    Ÿ  Available from 2011
    Ÿ  Typography, forms, buttons, charts, navigation and other
    interface components
    Ÿ  Integrates well with jQuery
    M

    View full-size slide

  18. 18
    Most popular project on github!
    M

    View full-size slide

  19. 19
    Let’s talk about JavaScript
    Ÿ  Back in 2008, there were too many JavaScript frameworks
    Ÿ  Now there is jQuery!
    M

    View full-size slide

  20. 20
    Spring @MVC and the View Layer
    Ÿ  Spring @MVC is neat and elegant on the controller side
    –  Form submission, Validation, File upload, testing…
    Ÿ  Spring @MVC is view-agnostic
    –  No much tooling for integration with CSS/JavaScript frameworks
    –  It’s your job to create the custom tags you need
    ▪  But that’s not hard!
    P

    View full-size slide

  21. 21
    Form fields: Without custom tags

    ${lastNameLabel}







    CSS div
    Label
    Form input
    Error message (if any)
    JSP
    M

    View full-size slide

  22. 22
    Using custom tags
    Ÿ  First create a tag (or tagx) file
    <%@ taglib prefix="form" uri="http://www.spring…org/tags/form" %>
    <%@ attribute name="name" required="true" rtexprvalue="true" %>
    <%@ attribute name="label" required="true" rtexprvalue="true" %>

    ${label}







    inputField.tag
    Custom tags are part of Java EE
    P

    View full-size slide

  23. 23
    Using custom tags
    Ÿ  Custom tag call Folder which contains
    custom tags





    JSP file
    1 line of code
    instead of 9!!
    P

    View full-size slide

  24. 24
    Some tags already exist!
    Ÿ  Dandelion for DataTables (nice addition to Spring @MVC)
    –  dandelion.github.com

    property="firstName" sortable="true" />
    property="lastName" sortable="true" />

    JSP file
    M

    View full-size slide

  25. 25
    Dandelion is based on
    jQuery Datatables and Bootstrap
    Ÿ  Click, sort, scroll, search, next/previous…
    Ÿ  PDF and Excel exports…
    M

    View full-size slide

  26. 26
    Spring Boot: the future of Spring applications?
    Ÿ  Spring Boot allows to reduce configuration a lot
    –  Based on Convention over configuration
    P

    View full-size slide

  27. 27
    Spring Boot: the future of Spring applications?
    Ÿ  Example with Spring Petclinic application
    Pom.xml Spring
    Configuration
    Properties Total
    Spring without
    Boot
    377 lines 350 lines 17 lines
    744
    lines
    Spring Boot 117 lines 130 lines 10 lines
    257
    lines
    65% less
    configuration code!!!
    Spring Petclinic without Boot: https://github.com/spring-projects/spring-petclinic/
    With Boot: https://github.com/FabienLauf/spring-petclinic
    P

    View full-size slide

  28. 28
    Spring Boot conventions
    Ÿ  Maven POM dependencies are much easier
    P

    View full-size slide

  29. 29
    Spring Boot conventions
    Ÿ  Spring Boot takes an opinionated approach to application
    decisions
    –  Example Opinion: Web applications should use Tomcat
    –  Example Opinion: JPA applications should use Hibernate
    Ÿ  What if you have different opinions?
    –  Run on Jetty, use EclipseLink
    Ÿ  No Problem!
    –  Simply override the default configuration
    P

    View full-size slide

  30. 30
    Cloud Foundry: new way to deploy Java apps!
    Ÿ  PaaS (Platform as a Service)
    Ÿ  Open Source
    Ÿ  Deploy and Scale in Seconds on Your choice of
    technologies

    View full-size slide

  31. 31
    Survey results!!

    View full-size slide

  32. 32
    Conclusion
    Ÿ  Once  upon  a  5me,  Java  community  was  unified  around  Struts!  
    Ÿ  JavaScript  and  CSS:  you  now  have  good  frameworks!  
    Ÿ  Spring  @MVC  now  is  the  most  popular  Web  framework  for  Java  
    Ÿ  Create  your  own  custom  tags  for  the  View  layer  
    Ÿ  Start  learning  Spring  Boot  and  Cloud  Foundry!  
    N

    View full-size slide