This is my third article about getting started
preface
Based on Spring4.0 design, SpringBoot not only inherits the original excellent features of the Spring framework, but also simplifies the whole construction and development process of Spring applications by simplifying configuration. In addition, By integrating a large number of frameworks, SpringBoot solves the problems of dependency package version conflicts and reference instability.
The development environment
Eclipse
JDK 1.8
Spring Boot 2.02.
Copy the code
The paper
Spring Boot is a new framework from the Pivotal team designed to simplify the initial setup and development process for new Spring applications. The framework uses a specific way to configure so that developers no longer need to define boilerplate configurations. In this way, Spring Boot aims to be a leader in the burgeoning field of rapid Application development.
The characteristics of
-
Create a stand-alone Spring application
-
Embedded Tomcat without the need to deploy a WAR file
-
Simplifying Maven Configuration
-
Automatic Spring configuration
-
Provides production-ready functions such as metrics, health checks, and external configuration
-
There is absolutely no code generation and no configuration requirement for XML
Used to introduce
At its most basic, Spring Boot is a collection of libraries that can be used by any project’s build system. For simplicity, the framework also provides a command-line interface that can be used to run and test Boot applications. The release version of the framework, including the integrated CLI (command line interface), can be manually downloaded and installed in the Spring repository. An easier way is to use the Groovy enVironment Manager (GVM), which handles the installation and management of the Boot version. You can run the GVM install Springboot command to install the Boot and CLI. Install Boot on OS X to use the Homebrew package manager. To complete the installation, first switch to the Pivotal repository using Brew Tap Pivotal /tap, and then execute the brew Install Springboot command.
Projects to be packaged and distributed rely on build systems like Maven or Gradle. To simplify dependency diagrams, Boot’s functionality is modular, and many dependencies can be added to a project by importing what Boot calls a “starter” module. To make it easier to manage dependent versions and use default configurations, the framework provides a parent POM that projects can inherit from.
The simplest Spring Boot project will follow
Pom 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>pro.demo</groupId>
<artifactId>SpringBootdemo</artifactId>
<version>0.0.1 - the SNAPSHOT</version>
<packaging>jar</packaging>
<name>SpringBootdemo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2. RELEASE</version>
<relativePath/> <! -- lookup parent from repository -->
</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>
<! -- Web dependency -->
<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>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Copy the code
Configuration file properties
The Application configuration file :application.properties can be empty or you can leave no information in it. The default port number is 8080
Start the class
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan("pro.demo")
public class SpringBootdemoApplication {
public static void main(String[] args){ SpringApplication.run(SpringBootdemoApplication.class, args); }}Copy the code
interface
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/app")
public class TestController {
@RequestMapping("/test")
@ResponseBody
public String testDemo() {
return "Hello World!"; }}Copy the code
conclusion
Play strange upgrade is always tortuous, simple Demo is introduced here, welcome to like exchange.