3. Before We Get Started…
• Join the channel: http://bit.do/spring-boot
• Direct link: https://gitter.im/tan9/spring-boot-training
• Sign in using your GitHub account
• Or sign up right now!
3
7. JavaConfig Keep Evolving
• @Bean & @Configuration since 3.0
• Get rid of XML configuration files.
• @ComponentScan, @Enable* and
@Profile since 3.1
• With WebApplicationInitializer powered by
Servlet 3, say goodbye to web.xml too.
• @Conditional since 4.0
• We’re able to filter beans programmatically.
7
9. Things Getting Complicated
• Spring seldom deprecates anything
• And offers little opinion or guidance.
• Older approaches remain at the top in search results.
• Bootstrapping can be painful
• Due to the sheer size and growth rate of the portfolio.
• Spring is an incredibly powerful tool…
• Once you get it setup.
Should you use spring boot in your next project? - Steve Perkins
https://steveperkins.com/use-spring-boot-next-project/ 9
12. Spring Boot
• Opinionated
• Convention over configuration.
• Production-ready non-functional features
• Embedded servers, security, metrics, health checks…
• Speed up
• Designed to get you up and running as quickly as
possible.
• Plain Java
• No code generation and no XML configuration.
12
13. System Requirements
• Spring Boot 1.3 requires Java 7+ by default
• Java 8 is recommended if at all possible.
• Can use with Java 6 with some additional configuration.
• Servlet 3.0+ container
• Embedded Tomcat 7+, Jetty 8+, Undertow 1.1+.
• Oracle WebLogic Server 12c or later.
• IBM WebSphere Application Server 8.5 or later.
• JBoss EAP 6 or later.
13
14. Boot With Apache Maven
14
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.cht</groupId>
<artifactId>inception</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
</parent>
<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- Package as an executable jar -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
20. YAML (YAML Ain’t Markup Language)
• Superset of JSON.
• UTF-8!
• Really good for hierarchical configuration data.
• But… can't be loaded via the @PropertySource.
20
my:
servers:
- dev.bar.com
- foo.bar.com
my.servers[0]=dev.bar.com
my.servers[1]=foo.bar.com
YAML
Java Properties
21. Executable JAR
• $ mvn package
• Build and package the project.
• Spring Boot will repackage it into an executable one.
• $ java -jar target/
inception-0.0.1-SNAPSHOT.jar
• It’s just running.
• The jar is completely self-contained, you can deploy and
run it anywhere (with Java).
21
23. Quick Start
• Spring Initializr Web Service
• http://start.spring.io
• SpringSourceTools Suite (eclipse-based)
• https://spring.io/tools/sts/all
• IntelliJ IDEA Ultimate (Costs $$$)
• https://www.jetbrains.com/idea/
• Or import Spring Initializr generated project from IntelliJ
IDEA Community Edition.
23
35. Metrics
• Gauge
• records a single value.
• Counter
• records a delta (an increment or decrement).
• PublicMetrics
• Expose metrics that cannot be record via one of those
two mechanisms.
35
39. @Order matters
• Hints for Spring Boot
• @AutoConfigureAfter
• @AutoConfigureBefore
• You still have to know what underlying
• Not every operation is idempotent or cumulative.
• WebSecurityConfigurerAdapter for example.
39
40. @ConfigurationProperties
• Naming things seriously
• There are only two hard things in Computer Science:
cache invalidation and naming things. -- Phil Karlton
• It will be an important part of your own framework!
• Generates properties metadata at compile time
• Located at META-INF/spring-configuration-
metedata.json.
• A Spring Boot-aware IDE will be great help for you.
40
43. JBoss EAP
• JBoss EAP v6.0 – 6.2
• Have to remove embedded server.
• JBoss EAP v6.x
• spring.jmx.enabled=false
• server.servlet-path=/*
• http://stackoverflow.com/a/1939642
• Multipart request charset encoding value is wrong.
• Have to downgrade JPA and Hibernate.
• JBoss EAP v7
• Haven’t tried yet.
43
44. Oracle WebLogic Server
• WebLogic 11g and below
• Not supported.
• WebLogic 12c
• Filter registration logic is WRONG!
• https://github.com/spring-projects/spring-
boot/issues/2862#issuecomment-99461807
• Have to remove embedded server.
• Have to downgrade JPA and Hibernate.
• Have to specify <wls:prefer-application-
packages/> in weblogic.xml.
44