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

Breaking the Magician's Code

Breaking the Magician's Code

Diving deeper into Spring Boot internals

Madhura Bhave

May 17, 2019
Tweet

More Decks by Madhura Bhave

Other Decks in Programming

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. Summary • There’s no such thing as magic • Follow

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