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

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.
主站蜘蛛池模板: 锡林郭勒盟| 屏山县| 方正县| 贡觉县| 大新县| 永平县| 乡宁县| 大冶市| 遵义县| 镇巴县| 左权县| 游戏| 常熟市| 枣强县| 原平市| 同仁县| 临澧县| 青神县| 汝阳县| 千阳县| 神木县| 丹巴县| 济宁市| 邯郸市| 米林县| 乐昌市| 赤峰市| 保山市| 新干县| 文山县| 湖口县| 武功县| 二连浩特市| 叶城县| 昌宁县| 泊头市| 鄂托克前旗| 峨眉山市| 西乌珠穆沁旗| 祁东县| 汉沽区|