Use of the @springbootapplication of springboot annotations

Source: Internet
Author: User

@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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.