A brief introduction to Spring Boot

Spring Boot itself does not provide the core features and extension functions of the Spring framework, but is used to develop a new generation of applications based on the Spring framework quickly and flexibly. That is, it is not intended as a solution to replace Spring, but rather as a tool that integrates closely with the Spring framework to enhance the Spring developer experience, and integrates a number of common third-party library configurations (such as Jackson, JDBC, Mongo, Redis, Mail, etc.). These third-party libraries in Spring Boot applications can be configured almost out-of-the-box. Most Spring Boot applications require very little configuration code, allowing developers to focus more on business logic

Build the SpringBoot project

Before building, let me introduce my environment:

Compiler: IDEa2017.1.2

The JDK: 1.8.0 comes with _77

Now that you have built a Maven project, you need to create the SpringBoot configuration file

Pom. XML file:

<? 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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> < modelVersion > 4.0.0 < / modelVersion > < groupId > Example - SpringBoot - Swagger - Group < / groupId > < artifactId > Example - SpringBoot - Swagger < / artifactId > < version > 1.0 - the SNAPSHOT < / version > < the parent > <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> < version > 1.4.0. RELEASE < / version > < relativePath / > < / parent > < properties > <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> < project. Reporting. OutputEncoding > utf-8 < / project. Reporting. OutputEncoding > < Java version > 1.8 < / Java version > </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
    </dependencies>

</project>
Copy the code

Configure the files under the Resource folder

Static: Stores static resources such as CSS, JS and image

Templates: These are HTML files that you can reference by default without having to configure a path

Application. properties: This file configures information about the SpringBoot project

Exampleapplication. Java: Startup class for SpringBoot, which needs to be placed outside the other classes

Application. The properties:

/ / port for server port = 8080

HTML, CSS and other file formats:

ExampleApplication. Java:

package com.example; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * Created by shuai on 2017/5/21. */ @SpringBootApplication public class ExampleApplication { public static void main(String[] args) { SpringApplication.run(ExampleApplication.class, args); }}Copy the code

DemoController.java:

package com.example.controller;

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

/**
 * Created by shuai on 2017/5/21.
 */
@Controller
@RequestMapping(value = "/api/demo")
public class DemoController {
    @RequestMapping(value = "/welcome")
    public String demoReturnSuccess() {return "welcome"; }}Copy the code

welcome.html:

<! DOCTYPE html> <html lang="en"> <head> <title> Welcome to SpringBoot</title> </head> <body> <h1> Welcome to SpringBoot</h1> </body> </ HTML >Copy the code

This simple SpringBoot project has been successfully created, run the exampleApplication.java file, and start successfully.

More spring boot configuration items please see download: developer.aliyun.com/article/741…