javantura v3 - spring boot under the hood– nicolas fränkel

24
SPRING BOOT UNDER THE HOOD @NICOLAS_FRANKEL

Category:

Technology


1 download

TRANSCRIPT

Page 1: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

SPRING BOOT UNDER THE HOOD@NICOLAS_FRANKEL

Page 2: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 2

ME, MYSELF AND I

Developer/Software -/Solution Architect• Java• As consultant

Page 3: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 3

HYBRIS, AN SAP COMPANY

Page 4: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

4@nicolas_frankel #springboot

Page 5: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 5

Page 6: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 6

SPRING BOOT ACTUATOR<dependency> <groupId> org.springframework.boot </groupId> <artifactId> spring-boot-starter-actuator </artifactId></dependency>

Page 7: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 7

/HEALTH{ "status" : "UP", "diskSpace" : { "status" : "UP", "total" : 499055067136, "free" : 254812135424, "threshold" : 10485760 }, "db" : { "status" : "UP", "database" : "HSQL Database Engine", "hello" : 1 } }

Page 8: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 8

SPRING BOOT

Works well until:• It doesn’t anymore•Or you want to change the

default behavior

Page 9: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 9

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>

Page 10: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 10

LET’S CHECK HOW IT WORKS

Page 11: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 11

STARTERS DEPENDENCIES

Page 12: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 12

SPRING-BOOT-AUTOCONFIGURE.JAR

Page 13: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 13

SPRING.FACTORIES

Page 14: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@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 {

}

Page 15: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 15

@CONDITIONAL

@ConditionalOnBean@ConditionalOnClass@ConditionalOnMissingBean@ConditionalOnPropertyetc.

Page 16: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 16

REMEMBER @PROFILE?@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.TYPE)public @interface Profile {

String[] value();}

Page 17: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@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();}

Page 18: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 18

@CONDITIONAL & CONDITION

Page 19: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 19

@CONDITIONAL & CONDITION

Enables calling of a @Bean-annotated method• In the context of a

@Configuration class

Page 20: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 20

ENOUGH TALK…

Time for DEMO

Page 21: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 21

OUT-OF-THE-BOX CONDITIONSCondition 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: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 22

COMPOSITE CONDITIONSCondition Description

AllNestedConditions AND condition

AnyNestedConditions OR condition

NoneNestedCondition NOT condition

Page 23: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

@nicolas_frankel #springboot 23

OUR OWN STARTER

Time for DEMO

Page 24: Javantura v3 - Spring Boot under the hood– Nicolas Fränkel

24

Q&A

@nicolas_frankel

http://blog.frankel.ch/@nicolas_frankel http://frankel.in/https://git.io/v2f3O