1. @SpringBootApplication = (default property) @Configuration + @EnableAutoConfiguration + @ComponentScan.
2. @Configuration: When you mention @Configuration, you should mention his partner @Bean. Using these two annotations, you can create a simple spring configuration class that can be used to replace the corresponding xml configuration file.
- <beans>
- <bean id = "car" class="com.test.Car">
- <property name="wheel" ref = "wheel"></property>
- </bean>
- <bean id = "wheel" class="com.test.Wheel"></bean>
- </beans>
is equivalent to:
- @Configuration
- public class Conf {
- @Bean
- public Car car() {
- Car car = new Car();
- car.setWheel(wheel());
- return car;
- }
- @Bean
- public Wheel wheel() {
- return new Wheel();
- }
- }
The @Configuration annotated class identifies that this class can use the Spring IoC container as the source of bean definitions. The @Bean annotation tells Spring that a method annotated with @Bean will return an object that should be registered as a bean in the Spring application context.
2. @EnableAutoConfiguration: Ability to automatically configure the context of spring, trying to guess and configure the bean class you want, usually automatically based on your classpath and your bean definition.
3. @ComponentScan: It will automatically scan all the classes marked with @Component under the specified package and register them as beans, of course, including the sub-annotations @Service, @Repository, @Controller under @Component.