官术网_书友最值得收藏!

Writing a Spring Boot application class

This class contains the main method where the execution starts. This main method will bootstrap the Spring Boot application, look at the configurations, and start the respective bundled containers such as Tomcat if executing web services:

package com.mycompany.product;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

@SpringBootApplication
public class ProductSpringApp {
publicstaticvoid main(String[] args) throws Exception {
SpringApplication.run(ProductSpringApp.class, args);
}
}

Note the annotation called @SpringBootApplication.

The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration, and @ComponentScan, which do the following:

  • @Configuration: This is a core Spring annotation. It tells Spring that this class is a source of the Bean definitions.
  • @EnableAutoConfiguration: This annotation tells Spring Boot to guess how you will want to configure Spring, based on the JAR dependencies that you have added. We have added the starter web and hence the application will be considered to be a Spring MVC web application.
  • @ComponentScan: This annotation tells Spring to scan for any components, for example, the RestController that we are going to write. Note the scan happens in current and child packages. Hence, the class having this component scan should be at the top of the package hierarchy.
主站蜘蛛池模板: 高密市| 来宾市| 平遥县| 东乡县| 六盘水市| 宣汉县| 乐东| 鄯善县| 汝南县| 县级市| 沭阳县| 松江区| 新干县| 保康县| 长岛县| 德阳市| 淅川县| 紫金县| 博罗县| 南宁市| 德惠市| 孟村| 延津县| 板桥市| 友谊县| 化德县| 叙永县| 邹平县| 赤壁市| 丰都县| 自贡市| 绍兴县| 舞钢市| 新野县| 通榆县| 澎湖县| 鄂托克前旗| 凌云县| 陆良县| 揭东县| 库尔勒市|