- Mastering Microservices with Java
- Sourabh Sharma
- 203字
- 2021-07-02 13:03:32
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.
推薦閱讀
- AngularJS入門與進階
- Spring技術(shù)內(nèi)幕:深入解析Spring架構(gòu)與設(shè)計
- 自己動手寫Java虛擬機
- C語言程序設(shè)計
- Hands-On Swift 5 Microservices Development
- Test-Driven Development with Django
- 后臺開發(fā):核心技術(shù)與應(yīng)用實踐
- 超簡單:用Python讓Excel飛起來(實戰(zhàn)150例)
- 數(shù)據(jù)結(jié)構(gòu)與算法詳解
- Scratch少兒編程高手的7個好習(xí)慣
- 秒懂算法:用常識解讀數(shù)據(jù)結(jié)構(gòu)與算法
- Storm Real-Time Processing Cookbook
- IPython Notebook Essentials
- Python快速編程入門
- Java 9 Cookbook