+ All Categories
Home > Technology > Spring Boot under the Hood with Nicholas Frankel

Spring Boot under the Hood with Nicholas Frankel

Date post: 21-Jan-2018
Category:
Upload: spring-by-pivotal
View: 434 times
Download: 0 times
Share this document with a friend
27
1 © 2016 Pivotal Spring Boot under the Hood Nicolas Fränkel , Senior Consultant, SAP hybris @ nicolas_frankel
Transcript
Page 1: Spring Boot under the Hood with Nicholas Frankel

1© 2016 Pivotal

Spring Boot under the Hood

Nicolas Fränkel, Senior Consultant, SAP hybris

@nicolas_frankel

Page 2: Spring Boot under the Hood with Nicholas Frankel

2

Me, Myself and I

@nicolas_frankel #springboot

Developer/Software -/Solution Architect

• Java

• As consultant

Page 3: Spring Boot under the Hood with Nicholas Frankel

3

hybris, an SAP company

@nicolas_frankel #springboot

Page 4: Spring Boot under the Hood with Nicholas Frankel

4 @nicolas_frankel #springboot

Page 5: Spring Boot under the Hood with Nicholas Frankel

5 @nicolas_frankel #springboot

Page 6: Spring Boot under the Hood with Nicholas Frankel

6

Spring Boot actuator

@nicolas_frankel #springboot

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

Page 7: Spring Boot under the Hood with Nicholas Frankel

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

} }

Page 8: Spring Boot under the Hood with Nicholas Frankel

8

Spring boot

Works well until:

• It doesn’t anymore

• Or you want to change the default behavior

@nicolas_frankel #springboot

Page 9: Spring Boot under the Hood with Nicholas Frankel

9

There’s no magic involved

@nicolas_frankel #springboot

Page 10: Spring Boot under the Hood with Nicholas Frankel

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

Page 11: Spring Boot under the Hood with Nicholas Frankel

11

Starters dependencies

@nicolas_frankel #springboot

Page 12: Spring Boot under the Hood with Nicholas Frankel

12

spring-boot-autoconfigure.jar

@nicolas_frankel #springboot

Page 13: Spring Boot under the Hood with Nicholas Frankel

13

spring.factories

@nicolas_frankel #springboot

Page 14: Spring Boot under the Hood with Nicholas Frankel

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

Page 15: Spring Boot under the Hood with Nicholas Frankel

15

@Conditional

@ConditionalOnBean

@ConditionalOnClass

@ConditionalOnMissingBean

@ConditionalOnProperty

etc.

@nicolas_frankel #springboot

Page 16: Spring Boot under the Hood with Nicholas Frankel

16

Remember @Profile?

@Retention(RetentionPolicy.RUNTIME)

@Target(ElementType.TYPE)

public @interface Profile {

String[] value();

}

@nicolas_frankel #springboot

Page 17: Spring Boot under the Hood with Nicholas Frankel

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

Page 18: Spring Boot under the Hood with Nicholas Frankel

18

@conditional & condition

@nicolas_frankel #springboot

Page 19: Spring Boot under the Hood with Nicholas Frankel

19

@conditional & condition

Enables calling of a @Bean-annotated method

• In the context of a @Configuration class

@nicolas_frankel #springboot

Page 20: Spring Boot under the Hood with Nicholas Frankel

20

Demo

Let’s play with

conditionals

@nicolas_frankel #springboot

Page 21: Spring Boot under the Hood with Nicholas Frankel

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

Page 22: Spring Boot under the Hood with Nicholas Frankel

22

Out-of-the-box conditions

@nicolas_frankel #springboot

Condition Description

AllNestedConditions AND condition

AnyNestedConditions OR condition

NoneNestedCondition NOT condition

Page 23: Spring Boot under the Hood with Nicholas Frankel

23

Demo

Our own starter

@nicolas_frankel #springboot

Page 24: Spring Boot under the Hood with Nicholas Frankel

24

Q&A

@nicolas_frankel #springboot

http://blog.frankel.ch/

@nicolas_frankel

http://frankel.in/

https://git.io/v2f3O

Page 25: Spring Boot under the Hood with Nicholas Frankel

25

Chicago: May 30, 31

New York: June 20-21

Atlanta: July 18-19

Page 26: Spring Boot under the Hood with Nicholas Frankel

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

Page 27: Spring Boot under the Hood with Nicholas Frankel

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


Recommended