- Mastering Microservices with Java 9(Second Edition)
- Sourabh Sharma
- 204字
- 2021-07-02 21:54:46
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.
推薦閱讀
- 零基礎搭建量化投資系統:以Python為工具
- Mastering Entity Framework
- RTC程序設計:實時音視頻權威指南
- Python高級機器學習
- Couchbase Essentials
- Unity 2018 Augmented Reality Projects
- Magento 2 Beginners Guide
- Delphi開發典型模塊大全(修訂版)
- Learning Unreal Engine Game Development
- 精益軟件開發管理之道
- Java 9:Building Robust Modular Applications
- Lync Server Cookbook
- MATLAB從入門到精通
- 流程讓管理更高效:流程管理全套方案制作、設計與優化
- Delphi Cookbook