Breaking the Magician's Code

Breaking the Magician's Code

Diving deeper into Spring Boot internals

Madhura Bhave

May 17, 2019

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

29 slides
  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!

More Decks by Madhura Bhave

Other Decks in Programming