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

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.

主站蜘蛛池模板: 龙山县| 平顺县| 三门峡市| 龙游县| 岐山县| 穆棱市| 津市市| 健康| 特克斯县| 涡阳县| 六枝特区| 七台河市| 瑞丽市| 宜兰县| 延寿县| 桂平市| 井研县| 个旧市| 吐鲁番市| 黔西| 沛县| 新巴尔虎右旗| 江安县| 溧阳市| 肇源县| 奉贤区| 赤城县| 陵川县| 荆门市| 龙口市| 孙吴县| 太仓市| 汉阴县| 城口县| 修水县| 阿拉善右旗| 台中县| 沂南县| 偃师市| 苗栗县| 右玉县|