What is the Spring Boot CLI
The spring boot CLI is the abbreviation for Spring boot Commad line and is the Spring Boot command lines tool. In the spring boot CLI, you can run the Groovy script and learn the spring boot prototype quickly and easily with simple Java syntax.
Spring Boot CLI Installation
Open the Spring Boot CLI download page, address: https://repo.spring.io/milestone/org/springframework/boot/spring-boot-cli. Download the required spring-boot-cli-2.0.0-bin.zip or spring-boot-cli-2.0.0-bin.tar.gz dependencies, unzip to the installation directory, and specify its bin directory to add environment variables.
Java is cross-platform, so the sping Boot CLI is also cross-platform. It can be installed in the Win, Linux and MAC environments.
Mac,linux environment installation, the code is as follows:
Installed in the Windows environment, the code is as follows:
With Homebrew installation, execute the following command:
With MacPorts installation, execute the following command:
The Spring Boot CLI can be installed in all of the above methods. After executing the command, then execute the following instruction to output the corresponding version to verify the installation success, the code is as follows:
Successful output will appear in the console:
Spring Boot CLI Hello World case
After installation, it is convenient to learn to use it under the Spring Boot CLI. For example, we learn how to write an example of Hello world, or use the Spring Boot CLI to send a simple RESTful service.
Create a new Hello.groovy file with the following code:
Then execute the following instruction to compile and run the application:
You can also --
configure property values by going out of the way. For example, configure the port number to 8081: spring run hello.groovy -- --server.port=9000
. When the console successfully outputs, open the browser, access the/hello address, you can get "hello,spring boot! "The result.
In addition, some common commands are described:
Help instructions can get more information about the instructions
Package the *.groovy file in the current directory into an executable jar file:
The following command is used to initialize the creation of a new project, such as an existing skeleton list dependency that initializes the project:
For example, we need web dependencies to implement the Web, and JPA relies on operational data sources. Then execute the following command:
Will get the My-project project, the project directory structure is as follows:
See official documentation: Https://docs.spring.io/spring-boot/docs/current/reference/html/cli-using-the-cli.html.
Summary
Spring Boot CLI, really suitable for beginners to learn OH.
Novice must See, Spring Boot CLI must be known