Spring Boot
Fabien Lauf
fabien.lauf@gmail.com
http://sg.linkedin.com/in/fabienlauf
Spring
PetClinc:
from
plain
Vanilla
Spring
to
Spring
Boot
Slide 2
Slide 2 text
The Former PetClinic Application
• Spring sample application
• Major update in March 2013
• Spring MVC, Spring Data-JPA, Hibernate JPA, JDBC,
Bootstrap, Dandelion, EhCache, logback
Slide 3
Slide 3 text
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!
Slide 4
Slide 4 text
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!
Slide 5
Slide 5 text
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?
Slide 6
Slide 6 text
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 ?
Slide 7
Slide 7 text
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
Slide 8
Slide 8 text
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.
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.
Slide 11
Slide 11 text
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
Slide 12
Slide 12 text
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-