How to quickly build a SpringBoot project

Earlier we learned about the background and characteristics of SpringBoot. In this section, we mainly introduce how to quickly build a SpringBoot project to improve daily development efficiency.

SpringBoot is a scaffolding for building applications. It was developed by Spring's core team in 2013 and released the first version in April 2014. It is a new open source lightweight framework. It is designed based on Spring 4.0, which not only inherits the original excellent features of the Spring framework, but also further simplifies the entire construction and development process of Spring applications by simplifying configuration. In addition, SpringBoot solves problems such as version conflicts of dependent packages by integrating a large number of frameworks.

Scaffolding address: Spring | Projects   ->  Spring Boot

Official document address (version 3.0.6 as of now): Overview (Spring Boot 3.0.6 API)

1. SpringBoot environment preparation

1) Environment preparation: Windows installation Java environment 

2) Development tools: Java development tool IntelliJ IDEA uses

3) Build the Maven environment, search the Internet by yourself, a lot.

4) SpringBoot version selection:

If you use JDK8, choose the 2.xx version.
Spring official website introduction: If you choose the 3.0.0 version of SpringBoot, the JDK must be at least 17.
Note: The version mismatch will cause the Application to fail.

5) This tutorial demonstrates dependency versions

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.7</version> <!--根据自行需要调整-->
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<!-- jdk版本 -->

<properties>
   <java.version>11</java.version> <!--JDK版本根据自行需要调整-->
</properties>

2. Quickly create a SpringBoot project

Directly use the official scaffolding to improve the efficiency of framework construction. Spring | Quickstart  ->  Spring Initializr

Step 1: Configure dependent parameters

 

Step 2: Click "GENERATECTRL +" to download the configured project framework, decompress it and import it into Idea.

The created project will include: startup class, application.properties (you can configure some startup and runtime parameters, such as application name, port number, etc.) and pom dependencies. We can directly update the dependency package.

illustrate:

1) Since springboot has built-in tomcat. If not configured, the default service port is 8080. My local port 8080 is occupied by other applications, so it is changed to 8888 here.

2) I already have spring boot 2.7.7 and JDK 11 locally, so I have adjusted the spring boot parent version and jdk version. You can refer to the previous version correspondence adjustment.

The dependencies are as follows,

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.7</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<!-- jdk版本 -->

<properties>
   <java.version>11</java.version>
</properties>

Step 3: Start the application.

If the following figure appears, it starts normally.

Step 4: Add a test controller for verification.

code show as below,

package com.xintu.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class SpringbootApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringbootApplication.class, args);
	}

	@GetMapping("/hello")
	public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
		return String.format("欢迎 %s 来到<a href=\"http://www.35xintu.com\">35新途</a>!", name);
	}

}

test verification,

that's all!

Guess you like

Origin blog.csdn.net/wangyongfei5000/article/details/130398061