01.Spring boot Serialization: Spring boot Introduction

Source: Internet
Author: User

1 Overview of Spring boot

Spring boot is the middle tier of the developer and spring itself framework, helping developers manage the configuration of the application, providing default processing based on common configurations in real-world development (ie, custom-better configuration), simplifying application development, simplifying application operations, and, in general, the purpose of spring Boot is designed to "simplify" and "speed up" the development of Java Web, simplifying the configuration that introduces or launches the associated spring functionality during development. The benefit is to reduce the developer's focus on the framework and to focus more on their business code.

At the same time, with the extension and practice of the micro-service concept, the streamlined concept of spring boot makes it an ideal choice for Java microservices Development, and it can be said that spring boot is actually a Java web framework for microservices. Today, Spring Boot has become a leader in the burgeoning field of rapid application development (rapid application development).

2 core features of Spring boot
  • Spring projects that can be run independently: Spring boot can run independently as a jar package.

  • inline servlet container: Spring boot can choose to embed Tomcat, jetty, or undertow without deploying the project as a war package.

  • simplified MAVEN configuration: Spring provides the recommended base POM file to simplify the MAVEN configuration.

  • automatic configuration spring:spring boot automatically configures the Spring framework based on project dependencies, greatly reducing the configuration to be used by the project.

  • provides production-ready functionality: Features that can be used directly in the production environment, such as performance metrics, application information, and application health checks.

  • No code generation and XML configuration: Spring boot does not generate code. All of spring's configurations are implemented without any XML configuration at all.

  • spring Boot incorporates a number of technical frameworks that can be configured to automatically correlate and configure integration with other frameworks.

  • Using the public number editor has a very headache problem-the pasted code, the format is garbled, and particularly ugly. This editor can solve this problem.

3. Introductory case

(1) integrating Maven in Eclipse development tools (readers can also contact the author for a tutorial on using the MAVEN framework) (2) Create a new Mavan Web project in eclipse named Hellotest

(3) Add the following configuration to the Pom.xml file:

<!--Joining this configuration means that spring boot will automatically select the appropriate--><parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version> </parent>

to build a spring boot-based application, you must first set the element to spring boot spring-boot-starter-parent,spring-boot-starter-parent is the core initiator of spring boot , with a large number of default configurations, such as automatic configuration, logging, and Yaml, which greatly simplifies our development. Elements suggest using the latest release version, and then the Spring boot module (such as the Spring-boot-starter-web module) will automatically select the most appropriate version to add, and subsequent configurations do not require the programmer to make the version number themselves. (4) Add the following configuration to the Pom.xml file:

<!--  Joining this configuration means that Spring boot will automatically select the appropriate--><dependency>    <groupid> org.springframework.boot</groupid>    <artifactid>spring-boot-starter-web</ Artifactid></dependency> 

spring boot contains a lot of starter modules, simply put, each starter module is a series of dependent package combinations. The Starter-web module, for example, is a common dependency package that includes some of the spring boot predefined web development, supporting full-stack web development, including Tomcat and SPRING-WEBMVC, while the spring Boot will automatically configure the integrated SPRINGMVC. Because Spring-boot-starter-parent is specified, the Web starter module here does not need to specify a version, and Spring boot automatically chooses the most appropriate version to add. The contents of the Pom.xml file after the modification are as follows:

<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>org.fkit.springboot</groupid>  <artifactid>hellotest</artifactid >  <version>0.0.1-snapshot</version>  <packaging>jar</packaging >  <name>hellotest</name>  <url>http://maven.apache.org</url>    <parent>        <groupId> Org.springframework.boot</groupid>        <artifactid> Spring-boot-starter-parent</artifactid>        <version> 1.5.6.release</version>   </parent>    <properties>        < project.build.sourceencoding>utf-8</project.build.sourceencoding>    </ properties>    <dependencies>        < Dependency>            <groupid> org.springframework.boot</groupid>             <artifactId>spring-boot-starter-web</artifactId>    </dependency>     <dependency>          < Groupid>junit</groupid>          <artifactid> junit</artifactid>          <version>3.8.1</ Version>          <scope>test</scope>      </dependency>     </dependencies></project>

pom.xml file modification is saved, Maven automatically downloads all the jar files needed, depending on the reader's network. (5) write the test code a. Write a simple Java class Hellocontroller.

  Program List:codes/01/hellotest/org/fkit /hellotest/hellocontroller.javaimport  org.springframework.web.bind.annotation.requestmapping;import  Org.springframework.web.bind.annotation.restcontroller;// restcontroller equivalent to   in SPRINGMVC @Controller  + @[email protected] class HelloController {    //  Maps " /hello "Request      @RequestMapping ("/hello ")     public String  Hello () {        return  " hello spring boot!"; The @restcontroller annotations used on the     }}HelloController  class are a combination of annotations, equivalent to @[email  in SPRINGMVC Protected] The role of a combination. Indicates that the request returns the string "Hello".

b. Modify the MAVEN default app class.

//  Program List:codes/01/hellotest/org/fkit/hellotest/app.javaimport  org.springframework.boot.springapplication;import  org.springframework.boot.autoconfigure.springbootapplication;//  @SpringBootApplication Specifies that this is a  spring  boot applications [email protected] class app {    public static  void main ( String[] args )     {         // SpringApplication  for classes that start the Spring app from the main method.         springapplication.run (App.class, args);     }} 

app class specifies that this is a spring boot application, which is also a combination annotation, equivalent to @configuration + @EnableAutoConfiguration + @ Componentscan, specifically in the follow-up "Spring boot core" focus on the explanation. The Springapplication class is used to start a spring app class from the Main method. The static Run method is called directly here. C. Start the spring boot project and right-execute the App.java class to run the main method. D. Test app when the Spring Boot project starts, the default access address is: http://localhost:8080/, according to previous Web project habits, the reader may ask, how is there no project path? This is the default setting for spring boot, and the project path is set directly to the root path. Test your app by entering a URL in the browser.

Http://localhost:8080/hello

The results are as follows:

If you have questions, please contact the reader, Spring boot is currently very hot and will continue to be updated later.

01.Spring boot Serialization: Spring boot Introduction

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.