(i) Springboot Basics-Introduction and HelloWorld Experience

Source: Internet
Author: User

1.SpringBoot Introduction:

Based on the official Springboot document description, buildanything with spring boot (build anything with spring boot, Bull x!). ), here is the official documentation (document address, interested can see: https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/# Boot-documentation):

  

      • Start the project within the second range;
      • Build anything--rest API, WebSocket, Web, streaming media, tasks, etc.;
      • Simplified security architecture;
      • Rich relational database and non-relational database support;
      • Embedded operating environment support, Tomcat,jetty and undertow;
      • Developer benefits, hot deployment, etc.;
      • Just a reliance on the work;
      • Can be productive, tracking, monitoring and other characteristics;
      • Support your common IDE tools;
2.SpringBoot Operating Environment:

JDK Environment: 1.8+;

Project Building tools: maven:3.2+;

Gradle: Compatible with 4;

servlet container:

Name Servlet Version

Tomcat 8.5

3.1

Jetty 9.4

3.1

Undertow 1.4

3.1

3.SpringBoot Initial Experience (HelloWorld):

1. Introduce the MAVEN dependency library:

1<?xml version= "1.0" encoding= "UTF-8"?>2<project xmlns= "http://maven.apache.org/POM/4.0.0"3Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >5<modelVersion>4.0.0</modelVersion>6 7<groupId>com.cn</groupId>8<artifactId>spring-boot-hello</artifactId>9<version>1.0-SNAPSHOT</version>Ten  One<properties> A<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> -<java.version>1.8</java.version> -</properties> the  -<parent> -<groupId>org.springframework.boot</groupId> -<artifactId>spring-boot-dependencies</artifactId> +<version>2.0.1.RELEASE</version> -</parent> +  A<dependencies> at<dependency> -<groupId>org.springframework.boot</groupId> -<artifactId>spring-boot-starter-web</artifactId> -</dependency> -</dependencies> -</project>
Pom.xml

2. Create a Startup class:

1  Packagecom.cn;2 3 Importorg.springframework.boot.SpringApplication;4 Importorg.springframework.boot.autoconfigure.SpringBootApplication;5 6 /**7 * @program: Spring-boot-example8 * @description: Start class9  * @author:Ten * @create: 2018-04-28 10:42 One  **/ A @SpringBootApplication -  Public classhelloapplication { -  the     /** - * @Description: - * @Param: [Class] Configuration class source class - * @Param: [args] Apply startup parameters +      * @return: void - * @Author: + * @Date: 2018/4/28 A      */ at      Public Static voidMain (string[] args) { -Springapplication.run (helloapplication.class, args); -     } -  -}
Helloapplication.java

3. Create a controller access to interface:

1  PackageCom.cn.controller;2 3 Importorg.springframework.web.bind.annotation.RequestMapping;4 ImportOrg.springframework.web.bind.annotation.RestController;5 6 /**7 * @program: Spring-boot-example8 * @description: Control layer: Helllocontroller9  * @author:Ten * @create: 2018-04-28 10:49 One  **/ A  - @RestController -  Public classHellocontroller { the  -     /** - * @Description: - * @Param: +      * @return: - * @Author: + * @Adress:http://localhost: 8080/hello A * @Date: 2018/4/28 at      */ -@RequestMapping ("Hello") -      PublicString Hello () { -         return"Hello world!"; -     } -  in}
Hellocontroller.java

4. Start the startup class, open the browser, enter Http://localhost:8080/hello access:

  

Returns HelloWorld to the page;

  Note:

      • @SpringBootApplication: Springboot Start-up class annotations, see the source found it is actually @springbootconfiguration, @EnableAutoConfiguration, @ Componentscan three sets of annotations (after the source code will have an advanced article, I think learning a thing first to learn its application and then learn its essence);
      • Springapplication.run (Helloapplication.class, args); The real boot code, will do some initialization operation, start the built-in listener, create key environment object and load configuration items, etc.
      • @RestController: Or to view source code discovery, it is a collection of @controller, @ResponseBody, it Spring4 after the newly added annotations, the original return JSON needs @responsebody and @controller mates , now one step is done;
      • @RequestMapping ("Hello") request mapping not much to say;

Complete Example: https://gitee.com/lfalex/spring-boot-example

Reference Official Document: https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-documentation

Copyright NOTICE: This article for Bo Master original article, reproduced please indicate the source, thank you!

(i) Springboot Basics-Introduction and HelloWorld Experience

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.