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

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.
主站蜘蛛池模板: 吉木乃县| 勃利县| 东丰县| 延长县| 安福县| 博湖县| 仪征市| 延津县| 温泉县| 新宾| 大城县| 宁安市| 鄂托克前旗| 柞水县| 三原县| 贺兰县| 永清县| 洪雅县| 沙河市| 武清区| 青海省| 年辖:市辖区| 玛曲县| 石台县| 集安市| 波密县| 深州市| 眉山市| 黄陵县| 东丰县| 隆回县| 竹北市| 通河县| 云和县| 渝北区| 南京市| 邹平县| 庆云县| 博白县| 加查县| 科技|