Ruthless not like sentimental bitter, an inch also into tens of millions of wisps.

preface

Spring Initializr is essentially a Web application that generates the Spring Boot project structure for you. While it does not generate application code, it does provide you with a basic project structure, which programming languages (Java,Kotlin,Groovy) build instructions for Maven or Gradle. All you need to do is write the application code.

Spring Initializr has several uses.

  1. throughWebInterface use.
  2. throughSpring Tool SuiteUse.
  3. throughIntelliJ IDEAUse.
  4. useSpring Boot CLIUse.

This example mainly explains the use of the Web interface and IntelliJ IDEA

Set up localstart.spring.io

Ensure that the Maven environment variables are installed locally and settings.xml has added the Aliyun source

 <mirror>
        <id>nexus-aliyun</id>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
</mirror>
Copy the code
  1. Download source code to build
    1. git clone https://github.com/spring-io/start.spring.io.git
    2. cd start.spring.io
    3. mvn clean install -DskipTestsThe installation takes a little longer time. Please wait patientlynodeandyarnRely on
  2. Run the application locally
    1. cd start-site
    2. mvn spring-boot:run
    3. And then visithttp://localhost:8080/

throughSpring InitializrtheWebinterface

In order to useSpring InitializrThe most direct way is to open it in a browserhttp://start.spring.ioYou should be able to see the following form, since it’s already set up locallySpring InitializrYou can also access it directlyhttp://localhost:8080/View the following form

The options on the top left of the form are whether you want to use Maven or Gradle to build your project, which programming language to write the code in, and which version of Spring Boot to use. The program generates Maven projects by default and uses the latest version of Spring Boot (non-milestone and snapshot versions), but you are free to choose other options.

At the bottom left side of the form is some basic information about the project you specified. At a minimum, you need to provide the project’s Group, Artifact, project name, project description, sign-up, packaging method, and dependent Java version. This information is used to generate Maven’s pom.xml file (or Gradle’s build. Gradle file).

The right side of the form asks you to specify project dependencies. The easiest way to do this is to type the name of the dependency in the text box. As a list of matching dependencies appears with your input, select one (or more) and the selected dependencies are added to the project.

Fill out the form, select the dependency, click the Generate button, and Spring Initializr will Generate a project for you. The browser will download the Artifact as a ZIP file (the file name depends on the contents of the Artifact field). Depending on your choice, the contents of the ZIP file will be slightly different. In any case, the ZIP file contains a very basic project to get you started developing applications using Spring Boot.

The decompression project directory is as follows:

Niocoder ├ ─ ─ HELP. Md ├ ─ ─ MVNW ├ ─ ─ MVNW. CMD ├ ─ ─ pom. The XML └ ─ ─ the SRC ├ ─ ─ the main │ ├ ─ ─ Java │ │ └ ─ ─ com │ │ └ ─ ─ niocoder │ │ └ ─ ─ Niocoder │ │ └ ─ ─ NiocoderApplication. Java │ └ ─ ─ resources │ ├ ─ ─ application. The properties │ ├ ─ ─ the static │ └ ─ ─ templates └ ─ ─ The test └ ─ ─ Java └ ─ ─ com └ ─ ─ niocoder └ ─ ─ niocoder └ ─ ─ NiocoderApplicationTests. JavaCopy the code

As you can see, there is almost no code in the project, except for a few empty directories, which contain the following things.

  • pom.xml: MavenBuild File Description
  • NiocoderApplication.java: one withmain()Method used to boot the application
  • NiocoderApplicationTests.java: An empty oneJUnitThe test class
  • application.properties: An empty onepropertiesFile, you can add configuration properties as needed

Even empty directories have meaning in Spring Boot applications. The static directory places the static content of your Web application (JavaScript, stylesheets, images, and so on). Also, as you will see later, the templates used to render model data are placed in the Templates directory.

You will most likely import Initializr generated projects into the IDE.

inIntelliJ IDEAIn creatingSpring Bootproject

To create a New Spring Boot application in IntelliJ IDEA, choose New > Project from the File menu. Select Customer and enter http://localhost:8080

Click next

The second screen of the Spring Boot Initialization wizard asks you to provide some basic information about the project, such as the project name, Maven Group and Artifact, Java version, and whether you want to build the project using Maven or Gradle. Once the project information is described, click the Next button to take you to the third screen

The third screen starts asking you what dependencies to add to your project. As before, the check boxes on the screen correspond to the Spring Boot startup dependency. Click Next to take you to the last screen of the wizard, and click finish to get an empty Spring Boot project in the IDE.

Public number Java dry goods