springBoot notes (a) @SpringBootApplication of magic

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_41885819/article/details/101030198

After the IDEA by quickly create a Spring Boot project, under Group root path will be annotated with a @SpringBootApplication startup class, but the class also has a particular, we are familiar with the main methods for performing the method can be started directly our Spring Boot project.

Sample code is as follows:

package com.wuwl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//开启组件扫描和自动配置
@SpringBootApplication
public class SpringQuickStartApplication {

    public static void main(String[] args) {
    	//负责启动引导应用程序
        SpringApplication.run(SpringQuickStartApplication.class, args);
    }

}

This type again springBoot SpringQuickStartApplication application has two roles, and boot configuration.

  • SpringQuickStartApplication Spring configuration is the main class, although Spring Boot auto-configuration feature eliminates a lot of the Spring configuration, but still need to configure a small amount to start the automatic configuration . Spring-opened @SpringBootApplication component scans and the Boot Spring of automatic configuration features. In fact, @SpringBootApplicationthe three together to achieve useful notes:

    • Spring is@Configuration marked with the class uses Java-based Spring configuration. Although the book will not write too much configuration, but we will be more inclined to use Java-based configuration rather than XML.

    • Spring-@ComponentScan enabled component scans, so you write Web controller class and other components can be automatically discovered and registered as a Spring application context in the Bean. This chapter will write later in a simple Spring MVC controllers, using @Controller annotated, so that the component scans to find it.

    • Spring Boot of@EnableAutoConfiguration this humble little notes can also be called @Abracadabra, this line is configured to open a magic Spring Boot automatically configured, so you do not have to write articles configured.

    • In earlier versions of Spring Boot, you need to mark these three notes on ReadingListApplication class, but from the beginning of Spring Boot 1.2.0, there @SpringBootApplication on the line.

  • SpringQuickStartApplication or a boot class. Spring Boot To run the application in several ways, which include traditional WAR file deployment. But here the main () method so that you can put in the command line of the application as an executable JAR file to run. Here passed a reference to the class SpringQuickStartApplication SpringApplication.run (), as well as command-line arguments, these things start applications.

Guess you like

Origin blog.csdn.net/qq_41885819/article/details/101030198