Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Breaking the Magician's Code - Diving deeper in...

Phil Webb
February 28, 2017

Breaking the Magician's Code - Diving deeper into Spring Boot internals

Presented @DevNexus '17

Phil Webb

February 28, 2017
Tweet

More Decks by Phil Webb

Other Decks in Technology

Transcript

  1. Meta-Annotations • Most Spring Annotations can be used as meta-annotations

    • Use in your own code • Used extensively in the framework: •@RestController •@GetMapping
  2. META-Annotations • @AliasFor for advanced mappings: @SpringBootConfiguration @EnableAutoConfiguration @ComponentScan public

    @interface SpringBootApplication { @AliasFor(annotation = EnableAutoConfiguration.class, attribute = "exclude") Class<?>[] exclude() default {}; @AliasFor(annotation = ComponentScan.class, attribute = "basePackages") String[] scanBasePackages() default {};
  3. Spring Factories • Dirt simple way to discover implementations •

    Similar to Java Service Loader • Simple properties file • /META-INF/spring.factories
  4. Conditions • @Conditional annotation • Condition interface public interface Condition

    { boolean matches( ConditionContext context, AnnotatedTypeMetadata metadata); }
  5. Spring Boot Code •ConditionalOnAClass -> ConditionalOnClass • MagicApplication -> SpringBootApplication

    • EnableMagicAutoConfiguration -> EnableAutoConfiguration • EnableMagicProperties -> EnableConfigurationProperties • *Configuration -> *AutoConfiguration
  6. Summary • There’s no such thing as magic • Follow

    the breadcrumbs • Annotations • Import Selectors • Spring Factories • Conditions • Use the source!