Don't be a headline party, Daniel will teach you how to create a SpringBoot project

1. Introduction to SpringBoot

SpringBoot itself was born for the simple and rapid development of Spring framework projects. On the basis of maven, the existing maven gav was encapsulated. The benefits of his advent to Java developers are self-evident.

Here are a few of his benefits, Jin Jin:

1. Automatic configuration, no need for xml configuration, automatic identification after passing jar;

2. Integrate third-party libraries through Starter, which can be used out of the box;

3. Embedded Servlet container, no war package deployment required;

4. Built-in health detection and measurement index functions;

5. Provide all-in-one packaging plug-ins.

There are too many advantages, not to list them one by one, I believe that the small partners who do Java development have read many related articles.

2. New SpringBoot project by SpringInitializ

There are two ways to create a SpringBoot project, online creation on the Spring official website and creation through IDE tools. Let me talk about the first way:

2.1 Enter SpringInitializr official website

Enter https://start.spring.io/ in the browser , enter the creation page, select or modify the corresponding options and names according to your needs.

image.png

2.2 Choose the framework dependency package you need

image.png

2.3 Build the project

The generated project has been downloaded as a compressed package, after decompression, you can open it with IDE.

image.png

2.4 Start the project

You can see that the created project directory is as follows, and three files are mainly generated. The IDE needs to download the dependency package to open the project. This process may be slow, please pay attention.

image.png

2.4.1pom.xml file, which contains the jar package that the project depends on, you can introduce the corresponding jar in the file if necessary in the future

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <groupId>com.JohanChan</groupId>
  <artifactId>demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>demo</name>
  <description>Demo project for Spring Boot</description>

  <properties>
    <java.version>1.8</java.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>org.junit.vintage</groupId>
          <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

</project>

2.4.2 application.properties file, the file is empty, the default Tomcat port is 8080, you can modify the port through server.port, most of the future spring configuration is done in this file.

image.png

2.4.3XXXApplication.java file, project startup class, program entry, important tag @SpringBootApplication.

image.png

2.5 Verification Project

Create the HelloController file, start the program, and enter the project in the browser.

package com.JohanChan.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloController {
  @RequestMapping("/")
  @ResponseBody
  public String hello() {
    return "Hello,SpringBoot!";
  }
}

image.png
The project has been successfully created and successfully accessed.

3. IDE creates SpringBoot project

3.1 Open idea, file->new->project

image.png

3.2. This method is similar to the first one, select the corresponding option and modify the package name and project name, all the way next

image.png

3.3 Select Springboot version and project dependency package

image.png

3.4 After opening, it is the same as the first method, so I won't repeat it.

The above is the whole content of this article, I hope it will be helpful to everyone's study, and I hope everyone will support you

The latest high-frequency interview questions collected in 2021 (all organized into documents), there are a lot of dry goods, including mysql, netty, spring, thread, spring cloud, jvm, source code, algorithm and other detailed explanations. There are also detailed learning plans and interviews. Questions, etc., friends who need to obtain these content, please add Q Junyang: 547998459

Guess you like

Origin blog.csdn.net/p1830095583/article/details/114753406