2
votes

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.

2
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
You may be looking for the various annotation postprocessors. - chrylis -cautiouslyoptimistic-
Got it. Thanks, Chrylis. - Jack Peng

2 Answers

3
votes

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.

0
votes

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.