@SpringBootApplication is the most important note for spring boot, which is used to configure the startup class quickly.
The previous user was using 3 annotations to annotate their main class. They were @configuration, @EnableAutoConfiguration, @ComponentScan. Since these annotations are generally used together, spring boot provides a unified annotation @springbootapplication.
@SpringBootApplication = (default property) @Configuration + @EnableAutoConfiguration + @ComponentScan.
[Java] View plain copy @SpringBootApplication public class Applicationmain {public static void main (string[] Ar GS) {Springapplication.run (application.class, args); } }
Explain @configuration separately, @EnableAutoConfiguration, @ComponentScan.
1, @Configuration: Mention @configuration will mention his partner @bean. Using these two annotations, you can create a simple spring configuration class that can be used in place of the corresponding XML configuration file.
[html] View plain copy <beans> <bean id = "Car" class= "Com.test.Car" > < Property name= "Wheel" ref = "Wheel" ></property> </bean> <bean id = "Wheel" class= " Com.test.Wheel "></bean> </beans>
Equivalent:
[java] View plain copy @Configuration public class conf { @Bean public car car () { car car = new car (); car.setwheel (Wheel ()); return car; } @ bean public wheel wheel () { return new wheel (); } } @Configuration Annotation Class identification This class can use the spring IOC container as the source of the bean definition. @Bean note tells Spring that an annotation method with @bean returns an object that should be registered as a bean in the context of the spring application.
2, @EnableAutoConfiguration: The ability to automatically configure the spring context, to try to guess and configure the Bean class you want, is usually automatically configured according to your classpath and your bean definition.
3, @ComponentScan: will automatically scan the specified package under all the @component class, and registered as a bean, of course, including @component sub-annotations @service, @Repository, @Controller.