1© 2016 Pivotal
Spring Boot under the Hood
Nicolas Fränkel, Senior Consultant, SAP hybris
@nicolas_frankel
2
Me, Myself and I
@nicolas_frankel #springboot
Developer/Software -/Solution Architect
• Java
• As consultant
3
hybris, an SAP company
@nicolas_frankel #springboot
4 @nicolas_frankel #springboot
5 @nicolas_frankel #springboot
6
Spring Boot actuator
@nicolas_frankel #springboot
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
7
/health
@nicolas_frankel #springboot
{"status" : "UP","diskSpace" : {
"status" : "UP","total" : 499055067136,"free" : 254812135424,"threshold" : 10485760
},"db" : {
"status" : "UP","database" : "HSQL Database Engine","hello" : 1
} }
8
Spring boot
Works well until:
• It doesn’t anymore
• Or you want to change the default behavior
@nicolas_frankel #springboot
9
There’s no magic involved
@nicolas_frankel #springboot
10
Configuration – pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</dependency>
@nicolas_frankel #springboot
11
Starters dependencies
@nicolas_frankel #springboot
12
spring-boot-autoconfigure.jar
@nicolas_frankel #springboot
13
spring.factories
@nicolas_frankel #springboot
14
@JPARepositoriesAutoConfiguration
@Configuration@ConditionalOnBean(DataSource.class)@ConditionalOnClass(JpaRepository.class)@ConditionalOnMissingBean({
JpaRepositoryFactoryBean.class,JpaRepositoryConfigExtension.class })
@ConditionalOnProperty(prefix = "spring.data.jpa.repositories",name = "enabled", havingValue = "true",matchIfMissing = true)
@Import(JpaRepositoriesAutoConfigureRegistrar.class)@AutoConfigureAfter(HibernateJpaAutoConfiguration.class)public class JpaRepositoriesAutoConfiguration {}
@nicolas_frankel #springboot
15
@Conditional
@ConditionalOnBean
@ConditionalOnClass
@ConditionalOnMissingBean
@ConditionalOnProperty
etc.
@nicolas_frankel #springboot
16
Remember @Profile?
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Profile {
String[] value();
}
@nicolas_frankel #springboot
17
This is the new @profile
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
@Documented
@Conditional(ProfileCondition.class)
public @interface Profile {
String[] value();
}
@nicolas_frankel #springboot
18
@conditional & condition
@nicolas_frankel #springboot
19
@conditional & condition
Enables calling of a @Bean-annotated method
• In the context of a @Configuration class
@nicolas_frankel #springboot
20
Demo
Let’s play with
conditionals
@nicolas_frankel #springboot
21
Out-of-the-box conditions
@nicolas_frankel #springboot
Condition Description
OnBeanCondition Checks if a bean is in the Spring factory
OnClassCondition Checks if a class is on the classpath
OnExpressionCondition Evalutates a SPeL expression
OnJavaCondition Checks the version of Java
OnJndiCondition Checks if a JNDI branch exists
OnPropertyCondition Checks if a property exists
OnResourceCondition Checks if a resource exists
OnWebApplicationCondition Checks if a WebApplicationContext exists
22
Out-of-the-box conditions
@nicolas_frankel #springboot
Condition Description
AllNestedConditions AND condition
AnyNestedConditions OR condition
NoneNestedCondition NOT condition
23
Demo
Our own starter
@nicolas_frankel #springboot
24
Q&A
@nicolas_frankel #springboot
http://blog.frankel.ch/
@nicolas_frankel
http://frankel.in/
https://git.io/v2f3O
25
Chicago: May 30, 31
New York: June 20-21
Atlanta: July 18-19
26
1. Core Spring
2. Spring Professional
Certification
3. Enterprise Spring
4. Enterprise Integration
Specialist Certification
Prerequisites
ILT | 2 days
Learn how to use Spring
Cloud Data Flow to manage
data processing use cases
Spring Cloud Data Flow
Developer
ILT & LOL | 2 days
Learn how to develop
Spring cloud native
applications using Spring
Cloud Services
Spring Cloud Services
Spring Training and Certification
1. Core Spring
2. Spring Professional
Certification
Prerequisites
ILT, LOL & ELT | 2 days
Learn how to create
applications using Spring
Boot
Spring Boot Developer
ILT, LOL & ELT | 2 days
Learn how to create
applications using Spring
Boot
Spring Boot Developer
Legend:ILT= Instructor Led Training
LOL= Live Online
ELT= eLearning
27
Learn More. Stay Connected.
Twitter: twitter.com/springcentral
YouTube: spring.io/video
LinkedIn: spring.io/linkedin
Pivotal.io: https://content.pivotal.io/spring-by-pivotal