SpringBoot profile

Spring Boot is an open source project published by the Spring community to help developers build projects quickly and easily. It uses custom over configuration to get your projects up and running quickly. Using Spring Boot, it’s easy to create a standalone (running JAR, built-in Servlet container, Tomcat, Jetty), production-level project based on the Spring framework. You can use SpringBoot with little or no configuration files.

SpringBoot core functions

  • Standalone Spring projects: Can be run independently as jar packages through java-jar xx.jar.
  • Embedded Servlet containers: You can choose to embed Tomcat, Jetty, and so on.
  • Providing starter simplified Maven configuration: A Maven project that uses spring-boot-starter-web automatically loads spring Boot dependency packages.
  • Automatic Spring configuration: Spring. Boot automatically configures beans for classes in jar packages and classes in the classpath.
  • Quasi-production application monitoring: Monitors running projects based on HTTP, SSH, and Telnet.
  • No code generation and XML configuration: mainly through conditional annotations.

SpringBoot project construction

IO /, fill in the relevant project information, JDK version, etc., will generate a maven project compression package, download decompression import IDE can be.

2. Direct creation under IDE, it is recommended to use STS(Spring Tool Suite) and IntelliJ IDEA to support direct construction. STS is Spring’s secondary development Tool based on Eclipse.

Spring Tool Suite: Create a New Spring Initializr project, fill in the project information and select the technology to set up the project as a Maven project.

IntelliJ IDEA: Create the Spring Starter Project, fill in the project information and select the technology to complete the Maven project creation.

3, Spring Boot CLI tool, using the command to create.

Add the spring-boot-starter-parent dependency to the parent of the Spring Boot project. This project is a Spring Boot project.

Project Construction Case

Case 1: Generate the SpringBoot project directly from the IDE1.Create New Project

2. Select a new Spring Initializr project

3. Fill groups and artifacts

4. Default Core

5.Finish, the SpringBoot project is created

6. The end result is as follows

Case 2: Manually build a Maven project and change it to a SpringBoot project by modifying pom.xml to add SpringBoot configuration

1. Create a Maven project

2. Fill groups and artifacts

3. The Maven project is created

4. Modify the Maven project pop. XML file and add SpringBoot configuration <project to add the parent dependency spring-boot-starter-parent

<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> The < version > 2.1.2. RELEASE < / version > < relativePath / > <! -- lookup parent from repository --> </parent>Copy the code

Note: Spring-boot-starter-parent is a special starter that provides maven default dependencies. After use, common package dependencies can omit the version tag.

5. Add Web support

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>RELEASE</version>
    <scope>compile</scope>
</dependency>
Copy the code

6. Add compiled plug-ins

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

6. Create the SpringbootApplication class and add the @SpringBootApplication annotation to enable SpringBoot automatic configuration

@RestController
@SpringBootApplication
public class SpringbootApplication {

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

    @RequestMapping("/")
    String index() {return "Hello My Spring Boot Demo"; }}Copy the code

7. Test the effect of starting the project, browser inputhttp://localhost:8080