First knowledge of Spring Boot

Source: Internet
Author: User

Overview

It simply introduces the features of spring boot and how to build a spring boot project.

What is Spring Boot

With the popularity of dynamic language, Java development is particularly cumbersome: a wide range of configurations, underground development efficiency, complex deployment processes and third-party technology inheritance is difficult.

In the above environment, Spring Boot was born. It uses "habits better than Configuration" (there are a lot of configurations in the project, and there is a built-in configuration that allows you to run your projects quickly without having to manually configure them). Using spring boot makes it easy to create a spring-based project that runs independently (running jars, inline servlet containers), quasi-production levels, and you can use spring boot to protect yourself from a small spring configuration.

Spring Boot Core Features

1: Spring Project running independently

Spring boot can run independently as a jar package, and running a Spring boot project requires only the Java-jar Xx.jar to run.

2: Inline servlet container

Spring boot can choose to embed Tomcat, jetty, or undertow, so we don't need to deploy the project as a war package.

3: Provides starter simplifies maven configuration

Spring provides a series of starter Pom to simplify the loading of MAVEN since.

4: Auto-Configure Spring

Spring boot automatically configures beans for the classes in the jar package based on the jar packages, classes in the classpath, which greatly reduces the configuration we want to use.

5: Quasi-production application monitoring

Spring boot provides monitoring of the runtime's projects based on HTTP, SSH, and Telnet.

6: No code generation and XML configuration

Spring boot is not implemented by code generation, but is implemented by conditional annotations, which is a new feature provided by spring4.x.

Spring4.x advocates the use of a combination of Java configuration and annotation configurations, and spring boot does not require any XML configuration to implement all of the spring configurations.

The advantages of Spring boot

1: Build projects quickly.

2: No configuration integration of the mainstream development framework.

3: The project can be run independently without the need for external dependency on the servlet container.

4: Provides run-time application monitoring.

5: Greatly improve the efficiency of development and deployment.

6: Natural integration with cloud computing.

Create a spring boot project using idea

1: New Spring INITIALIZR Project

2: Fill in Project information and select technology

Create complete

Spring Boot CLI

The Spring boot CLI is the console command tool provided by spring BOOT.

: http://repo.spring.io/release/org/springframework/boot/spring-boot-cli/(different versions available for download).

Unzip and configure the environment variables when the download is complete. The configuration process is similar to the configuration JDK, which is not mentioned here.

To create a project:

In console input command: Spring init--build=maven--java-version=1.8--dependencies=web--packaging=jar--boot-version=1.3.0.m1-- Groupid=con.gaof--artifactid=demo

A compressed package is then generated, which is a spring boot project. The current path of the console when the package placement path is compressed.

        

        

Create a spring boot project manually

In fact, the two methods above include the other way to create a spring boot project is simply to create a MAVEN project, just add the spring boot dependency.

We can create an empty MAVEN project with any development tool and add spring boot dependencies to make it a spring boot project.

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"3 xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">4     <modelversion>4.0.0</modelversion>5 6     <groupId>Com.example</groupId>7     <Artifactid>Demo</Artifactid>8     <version>0.0.1-snapshot</version>9     <Packaging>Jar</Packaging>Ten  One     <name>Demo</name> A     <Description>Demo Project for Spring Boot</Description> -  -     <Parent> the         <groupId>Org.springframework.boot</groupId> -         <Artifactid>Spring-boot-starter-parent</Artifactid> -         <version>2.0.1.RELEASE</version> -         <RelativePath/> <!--Lookup parent from repository - +     </Parent> -  +     <Properties> A         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> at         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> -         <java.version>1.8</java.version> -     </Properties> -  -     <Dependencies> -         <Dependency> in             <groupId>Org.springframework.boot</groupId> -             <Artifactid>Spring-boot-starter-web</Artifactid> to         </Dependency> +  -         <Dependency> the             <groupId>Org.springframework.boot</groupId> *             <Artifactid>Spring-boot-starter-test</Artifactid> $             <Scope>Test</Scope>Panax Notoginseng         </Dependency> -     </Dependencies> the  +     <Build> A         <Plugins> the             <plugin> +                 <groupId>Org.springframework.boot</groupId> -                 <Artifactid>Spring-boot-maven-plugin</Artifactid> $             </plugin> $         </Plugins> -     </Build> -  the  - </Project>
Pom.xml

A simple little example.

Once you know how to create a spring boot project, you might want to create one now to see the effect.

After the creation is complete, add the index method to the portal class and run the access.

1  PackageCom.example.demo;2 3 Importorg.springframework.boot.SpringApplication;4 Importorg.springframework.boot.autoconfigure.SpringBootApplication;5 Importorg.springframework.web.bind.annotation.RequestMapping;6 ImportOrg.springframework.web.bind.annotation.RestController;7 8 /**9 * @RestController:Ten * Make this Class A controller that can be accessed by the path.  One * @SpringBootApplication: A * Core annotations of the Spring boot project, the main purpose is to turn on automatic configuration.  -  */ - @RestController the @SpringBootApplication -  Public classDemoApplication { -     /** - * The main function is to start the project as a portal +      * @paramargs -      */ +      Public Static voidMain (string[] args) { ASpringapplication.run (demoapplication.class, args); at     } -  -@RequestMapping ("/") - String Index () { -         return"Hello Spring Boot"; -     } in}
Demo

First knowledge of Spring Boot

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.