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

Spring Boot presentation

Michael Isvy
September 12, 2014

Spring Boot presentation

(Singapore Spring User Group, September 4th 2014)

Sample app on github is available here:
https://github.com/FabienLauf/spring-petclinic/

Michael Isvy

September 12, 2014
Tweet

More Decks by Michael Isvy

Other Decks in Technology

Transcript

  1. The Former PetClinic Application •  Spring sample application •  Major

    update in March 2013 •  Spring MVC, Spring Data-JPA, Hibernate JPA, JDBC, Bootstrap, Dandelion, EhCache, logback
  2. Spring Boot •  « Spring Boot is designed to get

    you up and running as quickly as possible. » •  Wraps several Spring projects, many third-party libraries and provides default configurations for each. •  Groovy or Java. •  Gradle, Maven or CLI. •  1.0.0.RC1 released in January 2014 •  http://spring.io runs on Spring Boot! •  Boot is not Roo!
  3. A Web application in a tweet? •  Yes, with Groovy

    + Spring Boot CLI •  Java and Maven: –  pom.xml –  Spring Boot starters dependencies –  A Main class (your application is a jar!) •  The pom.xml is your only configuration file!
  4. Getting started Pom.xml Configuration Properties PetClinic 80 lines 9 imported

    artifacts 2 XML files 50 lines 0 file Spring Boot 25 lines 31 imported artifacts 2 Java classes 15 lines 0 file What are the minimum prerequisites for a “Hello world” in both cases?
  5. Persistence layer Pom.xml Configuration Properties DB initializer PetClinic 50 lines

    2 XML files 75 lines 1 file 16 lines Set up by user Spring Boot 10 lines 3 JavaConfig classes 15 lines 1 file 3 lines Set up by Spring Boot Often seen as a bottleneck for projects configurations, does Spring Boot enhances persistence layer set up ?
  6. View and Controller layers • Limitations with JSP: –  Not available

    with Jetty –  Works only if packaged as a war with embedded Tomcat –  Dandelion throws exceptions with JSP and embedded Tomcat Pom.xml Configuration Properties PetClinic 60 lines 2 XML files 75 lines 0 file Spring Boot 25 lines 1 JavaConfig class 20 lines 1 file 2 lines
  7. Custom configurations •  Custom Views –  Declare your customs Views

    with JavaConfig just as you do with your Controllers •  Profile specific @Configuration classes –  JavaConfig simpler than XML. •  EhCache @Configuration class –  But sometimes, JavaConfig can be non value added… •  Logback –  Still need an XML file but it’s included in Spring Boot’s parent starter.
  8. Final configurations Pom.xml Configuration Properties PetClinic 377 lines 77 imported

    artifacts 9 XML files 350 lines 2 files 17 lines Spring Boot 117 lines 79 imported artifacts 6 JavaConfig classes 130 lines 1 file 10 lines
  9. Going further •  Replace @Profile with Spring 4’s @Conditional or

    the Spring Boot enhanced : @ConditionalOnMissingBean and @ConditionalOnBean. •  Add RESTfull monitoring services provided by the actuator starter •  Update the application to Java 8 in order to get full advantage of Spring 4. •  Add Thymeleaf in order to have Dandelion working. •  Let’s do a little startup time test.
  10. Why should I use Spring Boot? PROS •  Simplifies the

    use of Spring technologies. •  Allows to experiment Spring by coding not by reading books. •  Saves days of work at beginning of a new project. •  Xml configuration still available. •  Doesn’t add aspects and doesn’t generate code. •  Production-ready. •  Provides RESTfull monitoring services CONS •  Not 0% configuration •  Java Config can be tricky •  Harder to TroubleShoot
  11. References •  The “PetClinic on Spring Boot” sources: https://github.com/FabienLauf/spring-petclinic • 

    Reference guide: http://docs.spring.io/spring-boot/docs/1.1.5.RELEASE/reference/ htmlsingle/ •  Spring Boot sources: https://github.com/spring-projects/spring-boot •  Spring Boot samples: https://github.com/spring-projects/spring-boot/tree/v1.1.5.RELEASE/ spring-boot-samples/ •  Nice tutorial: http://info.michael-simons.eu/2014/02/25/boot-your-application-with-