Build Spring Boot Hello World from scratch

Scene introduction

In this tutorial, we will use IntelliJ IDEA to build a simple Spring Boot project and deploy this project to the Alibaba Cloud server ECS.

background knowledge

Background knowledge
Spring Boot
Spring Boot is a very popular microservice framework in recent years. It has the characteristics of simplified configuration, fast construction, and embedded Tomcat or Jetty container. It allows developers to focus on business implementation and can be created based on Maven or Gradle plug-ins. JARs and WARs executed.

Cloud server ECS
(Elastic Compute Service, ECS for short) is an IaaS (Infrastructure as a Service)-level cloud computing service provided by Alibaba Cloud with outstanding performance, stability, reliability, and elastic expansion. The cloud server ECS eliminates the pre-preparation for purchasing IT hardware, allowing you to use the server as convenient and efficient as using public resources such as water, electricity, and natural gas, realizing out-of-the-box and elastic scaling of computing resources. Alibaba Cloud ECS continues to provide innovative servers to solve a variety of business needs and help your business development.

Step 1: Create resources (ECS is not activated)

1. Click on [Alibaba Cloud to build Spring Boot Hello World experience scene from scratch] ( https://developer.aliyun.com/adc/scenario/af334c34023e423785cdf06d9a92d692) and click to start experiencing the activation of resources, and then view the experimental resources.

2. Click on the free open create the required resources.

Step 2: Install the Java development environment

1. Download and install JDK8, see Java SE 8u261 for download address .

2. Configure Java environment variables.
a. Open a command window and execute the following commands.
Note: Before executing the command, please modify the JAVA_HOME parameter C:\Program Files\Java\jdk1.8.0_211 as your JDK installation directory.
The execution results are as follows.
Insert picture description here
b. Execute the following command to verify whether the environment variable configuration is successful.

java -version

The execution results are as follows.
Insert picture description here

Step 3: Install and configure IntelliJ IDEA

This step mainly introduces the use of IntelliJ IDEA to install the Spring Assistant plugin.
1. Download and install IntelliJ IDEA, see IntelliJ IDEA for download address .
2. Double-click to run IntelliJ IDEA.
3. On the IntelliJ IDEA startup interface, click Configure> Settings in turn.
Insert picture description here
4. Click Plugins and enter spring Assistant in the search bar. Finally, click Install to install the plug-in.
Insert picture description here
5. Click Restart IDE.
Insert picture description here

Step 4: Create a Spring Boot project

This step mainly introduces the use of Spring Assistant plug-in to build a simple Spring Boot project.
1. In the IntelliJ IDEA startup interface, click Create New Project.
2. Click Spring Assistant on the left, and then click Next.
Insert picture description here

Step 5: Package and upload the project to the ECS server

1. Pack the project.
a. Click Maven in the upper right corner of IDEA.
Insert picture description here
b. Double-click demo>Lifecycle>package in turn to start packaging.
Insert picture description here
The execution result is as follows, the location marked in the figure is the path of the jar package after packaging.
Insert picture description here
2. Open the terminal tool.

  • Windows: Open a command window.
  • MAC: Open the command line terminal Terminal.
    Windows users, please check whether the SSH tool is installed in the system. Check method:
    a. Enter the command ssh -V in the terminal.
    ssh -V

    If the SSH version is displayed, it means it has been installed, as shown in the figure below.
    Insert picture description here
    b. If it is not installed, please download and install the OpenSSH tool.

  • Upload the jar package to the ECS server.
    a. Execute the following commands on the command line.
    scp C:\Users\Administrator\IdeaProjects\demo\target\demo-0.0.1-SNAPSHOT.jar [email protected]:/root

    Explanation: Before executing the command, please replace the following parameters.

  • C:\Users\Administrator\IdeaProjects\demo\target\demo-0.0.1-SNAPSHOT.jar is the storage path of the jar package.
  • 47.xx.xx.xx is the public network IP of the ECS instance.
    The execution results are as follows.
    Insert picture description here
    b. Enter the login password of the created ECS cloud server.
    c. After the upload is successful, the following information will be displayed.
    Insert picture description here

Step 6: Connect to the ECS server

1. Enter the connection command ssh [username]@[ipaddress] in the terminal.
You need to replace username and ipaddress with the elastic public IP of the ECS server created in step 1. E.g:

ssh [email protected]

Insert picture description here
The command display results are as follows:
Insert picture description here

  1. Enter yes.
  2. After agreeing to continue, you will be prompted to enter the login password. The password is the login password of the ECS of the created cloud service.
    Insert picture description here
    After successful login, the following information will be displayed.
    Insert picture description here

Step 7: Run the Java project on ECS

1. Execute the following command to install the Java runtime environment.

yum -y install java-1.8.0*

2. Execute the following command to run the Java project.

java -jar demo-0.0.1-SNAPSHOT.jar

The execution results are as follows.
Insert picture description here

  1. Use a browser to visit http://<ECS Public IP>:8080.
    Returning to the following interface indicates that the project started successfully.
    Insert picture description here

Guess you like

Origin blog.51cto.com/14981263/2551254