- Spring Microservices
- Rajesh RV
- 300字
- 2021-07-02 16:28:29
Developing the Spring Boot microservice using the CLI
The easiest way to develop and demonstrate Spring Boot's capabilities is using the Spring Boot CLI, a command-line tool. Perform the following steps:
- Install the Spring Boot command-line tool by downloading the
spring-boot-cli-1.3.5.RELEASE-bin.zip
file from http://repo.spring.io/release/org/springframework/boot/spring-boot-cli/1.3.5.RELEASE/spring-boot-cli-1.3.5.RELEASE-bin.zip. - Unzip the file into a directory of your choice. Open a terminal window and change the terminal prompt to the
bin
folder.Ensure that the
bin
folder is added to the system path so that Spring Boot can be run from any location. - Verify the installation with the following command. If successful, the Spring CLI version will be printed in the console:
$spring –-version Spring CLI v1.3.5.RELEASE
- As the next step, a quick REST service will be developed in Groovy, which is supported out of the box in Spring Boot. To do so, copy and paste the following code using any editor of choice and save it as
myfirstapp.groovy
in any folder:@RestController class HelloworldController { @RequestMapping("/") String sayHello() { "Hello World!" } }
- In order to run this Groovy application, go to the folder where
myfirstapp.groovy
is saved and execute the following command. The last few lines of the server start-up log will be similar to the following:$spring run myfirstapp.groovy 2016-05-09 18:13:55.351 INFO 35861 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started 2016-05-09 18:13:55.375 INFO 35861 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 24 ms
- Open a browser window and go to
http://localhost:8080
; the browser will display the following message:Hello World!
There is no war file created, and no Tomcat server was run. Spring Boot automatically picked up Tomcat as the webserver and embedded it into the application. This is a very basic, minimal microservice. The @RestController
annotation, used in the previous code, will be examined in detail in the next example.
推薦閱讀
- 工程軟件開發(fā)技術(shù)基礎(chǔ)
- 程序設(shè)計(jì)與實(shí)踐(VB.NET)
- 大學(xué)計(jì)算機(jī)基礎(chǔ)實(shí)驗(yàn)教程
- Mastering Selenium WebDriver
- 零基礎(chǔ)玩轉(zhuǎn)區(qū)塊鏈
- Java EE框架整合開發(fā)入門到實(shí)戰(zhàn):Spring+Spring MVC+MyBatis(微課版)
- Unity Virtual Reality Projects
- Java程序員面試算法寶典
- Python面向?qū)ο缶幊蹋簶?gòu)建游戲和GUI
- KnockoutJS Starter
- RSpec Essentials
- C語言程序設(shè)計(jì)
- Go語言精進(jìn)之路:從新手到高手的編程思想、方法和技巧(2)
- Python項(xiàng)目實(shí)戰(zhàn)從入門到精通
- SAP Web Dynpro for ABAP開發(fā)技術(shù)詳解:基礎(chǔ)應(yīng)用