Use Spring Initializr to build Spring Boot projects

In addition to using the Maven method to build the Spring Boot project, you can also quickly build the Spring Boot project through the Spring Initializr method. In essence, Spring lnitializr is a web application that provides a basic project structure that can help us quickly build a basic Spring Boot project. The following explains how to use the Spring Initializr method to build a Spring Boot project. The specific steps are as follows.

1. Create a Spring Boot project

Open IDEA, select [Create New Project] to create a new project, and in the pop-up "New Project" interface, select the [Spring Initializr] option on the left to quickly build the Spring Boot project, as shown in the figure.

"Project SDK" is used to set the JDK version used to create the project. Here, use the JDK version initialized before; use the default initialization service address "https" under "Choose lnitializr Service URL. " ://start.spring.io "to create a Spring Boot project (note that when using the quick way to create a Spring Boot project, the host must be connected to the Internet). Then click the [Next] button to enter the next step, as shown in the figure.

Set Group to com.iheima, Artifact to chapter01, and use default values ​​for other options. Click the [Next] button to enter the Spring Boot scene dependency selection interface, as shown in the figure.

In the interface shown in the above figure, "Project SDK" is used to set the JDK version used to create the project. Here, just use the JDK version that was initialized before; under "Choose Initializr Service URL." (select the initialization service address) Use the default initialization service address " https://start.spring.io " to create a Spring Boot project (note that when using the quick way to create a Spring Boot project, the host must be in a networked state). Then click the [Next] button to enter the next step, as shown in the figure.

In the Spring Boot scene dependency selection interface shown above, it is mainly divided into four parts, which are described in detail as follows.

(1) The Spring Boot version can be selected in the middle of the top of the page, and the latest stable version is displayed by default. If you want to customize the project version number, you need to enter the pom and xml files of the project, and specify the version number in the corresponding dependent tag.

(2) The left side of the page summarizes the development scenarios. Each development scenario will contain a variety of technical implementation solutions, while providing a variety of integrated module dependencies. For example, under the "Web" option, a lot of dependency support for web development is integrated; under the "Template Engines" option, dependency support for front-end template engines is integrated.

(3) The middle of the page shows the dependent modules included in the development scenario. For example, when the Web development scenario on the left side of the page is selected, multiple dependent modules integrated and supported in the Web development scenario will appear in the middle of the page, including Web and Reactive Web.

(4) The selected dependent modules are displayed on the right side of the page. When the user selects some dependent modules in a development scenario, the selected dependent modules will be displayed in this area, and these dependencies will be automatically imported into the subsequently created Spring Boot project.

Here, select the Web dependency in the Web development scenario. Click the [Next] button to enter the interface for filling in the project name and path, as shown in the figure below.

Project name generates a project name consistent with Artifact by default, and Project location uses the address selected by the last created project by default. Of course, the options on the page can be customized. Click the [Finish] button to complete the project creation.

So far, the Spring Boot project has been created. The directory structure of the created Spring Boot project is shown in the figure.

The Spring Boot project built using Spring lnitializr will generate project startup classes, folders for storing front-end static resources and pages, configuration files for writing project configurations, and test classes for project unit testing by default. Open and view the automatically generated project startup class Chapter01Application and the project dependency management file pom.xml, the contents of which are shown in the following two files respectively.
 

Create a Controller for web access

@RestController
public class HelloController {
@GetMapping("/hello")
 public String hello(){
    return "hello Spring Boot";
  }
}

Run the main program of the chapter01 project to start the class Chapter01Application. After the project runs successfully, visit "http:/Mocalhost:8080/hello" on the browser, as shown below.

As can be seen from the figure, the output of the page is "hello SpringBoot". So far, the Spring Boot project built using the Spring Initializr method is completed.

Guess you like

Origin blog.csdn.net/Blue92120/article/details/132140705