java day lviv - spring boot under the hood

24
SPRING BOOT UNDER THE HOOD @NICOLAS_FRANKEL

Upload: nicolas-frankel

Post on 17-Jan-2017

249 views

Category:

Software


4 download

TRANSCRIPT

Page 1: Java Day Lviv - Spring Boot under the hood

SPRING BOOT UNDER THE HOOD@NICOLAS_FRANKEL

Page 2: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 2

ME, MYSELF AND I Developer/Software

-/Solution Architect• Java• As consultant

Page 3: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 3

HYBRIS, AN SAP COMPANY

Page 4: Java Day Lviv - Spring Boot under the hood

4@nicolas_frankel #springboot

Page 5: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 5

Page 6: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 6

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

Page 7: Java Day Lviv - Spring Boot under the hood

@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: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 8

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

default behavior

Page 9: Java Day Lviv - Spring Boot under the hood

@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: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 10

LET’S CHECK HOW IT WORKS

Page 11: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 11

STARTERS DEPENDENCIES

Page 12: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 12

SPRING-BOOT-AUTOCONFIGURE.JAR

Page 13: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 13

SPRING.FACTORIES

Page 14: Java Day Lviv - Spring Boot under the hood

@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: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 15

@CONDITIONAL@ConditionalOnBean@ConditionalOnClass@ConditionalOnMissingBean@ConditionalOnPropertyetc.

Page 16: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 16

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

String[] value();}

Page 17: Java Day Lviv - Spring Boot under the hood

@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: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 18

@CONDITIONAL & CONDITION

Page 19: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 19

@CONDITIONAL & CONDITIONEnables calling of a @Bean-annotated method• In the context of a

@Configuration class

Page 20: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 20

ENOUGH TALK…

Time for DEMO

Page 21: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 21

OUT-OF-THE-BOX CONDITIONSCondition DescriptionOnBeanCondition Checks if a bean is in the Spring factoryOnClassCondition Checks if a class is on the classpathOnExpressionCondition Evalutates a SPeL expressionOnJavaCondition Checks the version of JavaOnJndiCondition Checks if a JNDI branch existsOnPropertyCondition Checks if a property existsOnResourceCondition Checks if a resource existsOnWebApplicationCondition Checks if a WebApplicationContext exists

Page 22: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 22

COMPOSITE CONDITIONSCondition DescriptionAllNestedConditions AND conditionAnyNestedConditions OR conditionNoneNestedCondition NOT condition

Page 23: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 23

OUR OWN STARTER

Time for DEMO

Page 24: Java Day Lviv - Spring Boot under the hood

@nicolas_frankel #springboot 24

Q&A

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