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

Making a sample REST application executable

Create a RestSampleApp class with the annotation SpringBootApplication. The main() method uses Spring Boot's SpringApplication.run() method to launch an application.

We will annotate the RestSampleApp class with the @SpringBootApplication annotation that adds all of the following tags implicitly:

  • The @Configuration annotation tags the class as a source of bean definitions for the application context.
  • The @EnableAutoConfiguration annotation indicates that Spring Boot is to start adding beans based on classpath settings, other beans, and various property settings.
  • The @EnableWebMvc annotation is added if Spring Boot finds spring-webmvc on the classpath. It treats the application as a web application and activates key behaviors such as setting up DispatcherServlet.
  • The @ComponentScan annotation tells Spring to look for other components, configurations, and services in the given package:
package com.packtpub.mmj.rest; 
 
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
 
@SpringBootApplication 
public class RestSampleApp { 
 
    public static void main(String[] args) { 
        SpringApplication.run(RestSampleApp.class, args); 
    } 
} 

This web application is 100 percent pure Java and you don't have to deal with configuring any plumbing or infrastructure using XML; instead, it uses the Java annotation that is made even simpler by Spring Boot. Therefore, there wasn't a single line of XML except pom.xml for Maven. There wasn't even a web.xml file.

主站蜘蛛池模板: 沁水县| 龙海市| 鲁山县| 连江县| 禹城市| 藁城市| 错那县| 香格里拉县| 侯马市| 宣威市| 阳江市| 方正县| 德庆县| 阿克苏市| 安西县| 旺苍县| 蒙山县| 阳山县| 新田县| 虹口区| 武宣县| 大城县| 西丰县| 湘潭市| 青冈县| 浙江省| 莫力| 云霄县| 喀什市| 县级市| 沙田区| 中超| 疏勒县| 阳高县| 电白县| 轮台县| 屏南县| 慈利县| 河北区| 五寨县| 三门峡市|