4

I don't understand how the SpringBootApplication shortcut works. Specifically I don't understand how the individual sub annotations like @ComponentScan and @EnableAutoConfiguration get passed onto the actual application class as if they were written explicitly there. I searched spring boot's code base for SpringBootApplication expecting to see code that looks for the "SpringBootApplication" string before applying these individual annotations but did not see any. Can someone explain this? Thanks.

Jack Peng
  • 576
  • 5
  • 19

2 Answers2

4

The @SpringBootApplication annotation is an annotation that is annotated with, among others, the annotations @ComponentScan and @EnableAutoConfiguration you mentioned. Instead of scanning for @SpringBootApplication, Spring internally scans for these (implicit) annotations and does its magic accordingly.

C-Otto
  • 5,615
  • 3
  • 29
  • 62
1

http://www.journaldev.com/7989/key-components-and-internals-of-spring-boot-framework

And also Spring Boot reduces defining of Annotation configuration. If we use @SpringBootApplication annotation at class level, then Spring Boot AutoConfigurator will automatically add all required annotations to Java Class ByteCode.

==> actually i can't find the code in spring boot autoconfig that does this.

Jack Peng
  • 576
  • 5
  • 19