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

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.

主站蜘蛛池模板: 裕民县| 沾化县| 荔浦县| 富顺县| 田林县| 布拖县| 嘉鱼县| 安丘市| 达日县| 西吉县| 龙口市| 宜川县| 集贤县| 永善县| 广灵县| 芜湖县| 潜山县| 百色市| 攀枝花市| 万安县| 新民市| 满洲里市| 伊金霍洛旗| 南岸区| 元谋县| 赞皇县| 东源县| 洪洞县| 临漳县| 长白| 额尔古纳市| 林口县| 邢台县| 海门市| 油尖旺区| 建始县| 新竹县| 瓦房店市| 邛崃市| 宜都市| 罗江县|