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

Making a sample RESTapplication executable

Create a RestSampleApp class using the SpringBootApplication annotation. 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.

主站蜘蛛池模板: 桦南县| 黄平县| 咸丰县| 洛川县| 南江县| 济源市| 金山区| 津南区| 谢通门县| 萨嘎县| 凭祥市| 登封市| 临城县| 柯坪县| 昌平区| 岳阳县| 万荣县| 新邵县| 墨脱县| 兴城市| 嘉黎县| 抚远县| 武鸣县| 灵丘县| 广州市| 威宁| 新蔡县| 兰坪| 博客| 灌阳县| 隆昌县| 双柏县| 沿河| 区。| 共和县| 襄垣县| 通道| 都安| 宣汉县| 大埔县| 博罗县|