java day lviv - spring boot under the hood
TRANSCRIPT
SPRING BOOT UNDER THE HOOD@NICOLAS_FRANKEL
@nicolas_frankel #springboot 2
ME, MYSELF AND I Developer/Software
-/Solution Architect• Java• As consultant
@nicolas_frankel #springboot 3
HYBRIS, AN SAP COMPANY
4@nicolas_frankel #springboot
@nicolas_frankel #springboot 5
@nicolas_frankel #springboot 6
SPRING BOOT ACTUATOR<dependency> <groupId> org.springframework.boot </groupId> <artifactId> spring-boot-starter-actuator </artifactId></dependency>
@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 } }
@nicolas_frankel #springboot 8
SPRING BOOTWorks well until:• It doesn’t anymore•Or you want to change the
default behavior
@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>
@nicolas_frankel #springboot 10
LET’S CHECK HOW IT WORKS
@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@ConditionalOnPropertyetc.
@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 & CONDITIONEnables calling of a @Bean-annotated method• In the context of a
@Configuration class
@nicolas_frankel #springboot 20
ENOUGH TALK…
Time for DEMO
@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
@nicolas_frankel #springboot 22
COMPOSITE CONDITIONSCondition DescriptionAllNestedConditions AND conditionAnyNestedConditions OR conditionNoneNestedCondition NOT condition
@nicolas_frankel #springboot 23
OUR OWN STARTER
Time for DEMO
@nicolas_frankel #springboot 24
Q&A
http://blog.frankel.ch/@nicolas_frankel http://frankel.in/https://git.io/v2f3O