@springbootapplication Annotations in spring boot

Source: Internet
Author: User

In spring boot, use @springbootapplication to specify that the class is the application startup class.

Automatically scans for the corresponding annotations under the current class and sub packages register as spring beans,

The application is started in the main method of the class by using the Springapplication Run method.

eg

[Java] view plain copy package Com.lanhuigu;   Import org.springframework.boot.SpringApplication;      Import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Springbootapp {public static void main (string[] args) {Springapp       Lication.run (Springbootapp.class, args); Using @springbootapplication annotations is equivalent to using @configuration @EnableAutoConfiguration @ComponentScan

The default properties of these three annotations, and the use of @springbootapplication can also be used to engage @enableautoconfiguration @ComponentScan.

Where @componentscan is useful, you can specify that scanning some packages under the following annotations are automatically registered as spring beans:

@Component, @Service, @Repository, @Controller, @Entity and so on.

eg

[Java]   View plain  copy package com.lanhuigu;      Import  org.springframework.boot.SpringApplication;   import  org.springframework.boot.autoconfigure.springbootapplication;   import  org.springframework.context.annotation.componentscan;      @SpringBootApplication     @ComponentScan (basepackages = {"Com.lanhuigu", "COM.GHG"})// string[]   Public  class SpringBootApp {               Public static void main ( String[] args )  {            springapplication.run (Springbootapp.class, args);        }  }  

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.