Related information about springboot

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.

  1. <beans>  
  2.     <bean id = "car" class="com.test.Car">  
  3.         <property name="wheel" ref = "wheel"></property>  
  4.     </bean>  
  5.     <bean id = "wheel" class="com.test.Wheel"></bean> 
  6. </beans>  


is equivalent to:

  1. @Configuration  
  2. public class Conf {  
  3.     @Bean  
  4.     public Car car() {  
  5.         Car car = new Car();  
  6.         car.setWheel(wheel());  
  7.         return car;  
  8.     }  
  9.     @Bean   
  10.     public Wheel wheel() {  
  11.         return new Wheel();  
  12.     }  
  13. }  

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325308570&siteId=291194637