Download - jDays - Spring Boot under the Hood
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 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@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 & CONDITION
Enables 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 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
@nicolas_frankel #springboot 22
COMPOSITE CONDITIONSCondition Description
AllNestedConditions AND condition
AnyNestedConditions OR condition
NoneNestedCondition 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