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.
Asked
Active
Viewed 4,262 times
4
-
See also http://stackoverflow.com/questions/18189980/how-do-annotations-work-internally/18202623#18202623 – chrylis -cautiouslyoptimistic- Mar 02 '17 at 20:16
-
Thanks, Chrylis. I'm now looking for the code in spring that actually looks up the annotations on top of the annotation and does the processing. – Jack Peng Mar 02 '17 at 21:02
-
You may be looking for the various annotation postprocessors. – chrylis -cautiouslyoptimistic- Mar 02 '17 at 21:51
2 Answers
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
-
I see. Can you point me to the code that scans for these implicit annotations? I'm curious. Thanks. – Jack Peng Mar 02 '17 at 20:48
-
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