Spring Boot Tutorial-1. Brief introduction

Source: Internet
Author: User
Tags spring boot actuator spring boot tutorial

First, guided tour

This article mainly introduces the following parts:
1. What is Spring Boot?
2. Why use spring Boot?
3. What features does Spring boot offer?
4. How do I use Spring Boot?
5. What are the disadvantages of Spring boot?

Second, what is Spring Boot?

Spring Boot is a new framework provided by the pivotal team designed to simplify the initial setup and development of new spring applications.
The framework uses a specific approach (inheriting starter, which contracts precedence over configuration) to configure, which eliminates the need for developers to define boilerplate configurations. In this way, boot is committed to becoming a leader in the burgeoning field of rapid application development (rapid application development).
Spring boot is not a framework, fundamentally, it is a collection of libraries, and a MAVEN or Gradle project imports the appropriate dependencies to use spring boot and does not have to manage the versions of these libraries yourself.
Currently the latest stable version is 1.3.6.release,github address: https://github.com/spring-projects/spring-boot

Third, why use spring Boot?

Spring boot is designed to simplify the configuration of the spring project, making it easier for jar dependency management and application compilation and deployment. Spring Boot provides an automated configuration that uses spring boot, and you only need to write the necessary code and configure the required properties.
With spring Boot, you can generate a basic spring Web application with just about 20 lines of code, and built-in Tomcat, the Fat jar package built to run directly through Java-jar.
The following features make spring boot a great fit for microservices, with spring boot and Spring cloud and Docker technology to build microservices and deploy to the cloud:

    • An executable jar is a standalone service
    • It is easy to load into a container, and each service can run in its own container (for example, Docker)
    • Configuration and deployment with a single script, ideal for cloud deployments, and easy to scale automatically

Simply put, spring boot makes coding easier, makes configuration easier, makes deployment easier, and makes monitoring easier.

Iv. what features does Spring boot offer? 1. No need to manually manage versions of dependent jar packages

Spring boot manages all dependent versions that it provides through the Spring Boot starter project, and these dependent versions are upgraded when spring boot is upgraded. You do not need to specify a version number, but you can also override the default value of Springboot by customizing the version number. Each version of boot has a corresponding base spring version, and it is not recommended to explicitly specify the Spring edition.
For example, when using MAVEN, simply including Spring-boot-starter-web in the Pom introduces the dependency of spring MVC and Tomcat.
Here are some of the starters that spring boot provides under the Org.springframework.boot group:

name Description
Spring-boot-starter Core Spring Boot starter, including automatic configuration support, logs and YAML
Spring-boot-starter-actuator Production-ready features to help you monitor and manage your applications
Spring-boot-starter-web Support for full-stack web development, including Tomcat and SPRING-WEBMVC
Spring-boot-starter-aop Support for aspect-oriented programming, including SPRING-AOP and ASPECTJ
Spring-boot-starter-data-jpa Support for the Java Persistence API, including SPRING-DATA-JPA, Spring-orm, and Hibernate
Spring-boot-starter-jdbc Support for the JDBC database
Spring-boot-starter-security Support for the spring-security
2. Automatic configuration, no XML required

Spring boot tries to automatically configure your app based on the jar dependencies you add. For example, if HSQLDB is in the classpath and you do not manually configure any DB connection beans, spring boot automatically configures a memory db.
With the @enableautoconfiguration or @springbootapplication annotations, with the @configuration annotation class, you can achieve the purpose of automatic configuration.
This automatic configuration of Spring boot is non-intrusive, and you can define your own configuration or bean instead of automatically configured content.

3. Executable Jar Package

Spring boot packages The app into an executable jar package file by default, and runs the app with the Java-jar command once the build is successful.
Java does not provide any standard way to load the jar packages embedded in the jar package. Common developers use shadow jar technology to solve this problem. A shadow jar simply packs all of the jar's classes into a single super jar package. The problem with this is that it's hard to tell which libraries are actually available in your app, and that files with the same name in multiple jar files are also an issue.
Spring Boot is a straightforward alternative to using the following file format to allow you to nest jar packages directly:

The dependencies need to be placed in the internal Lib folder.

What is the principle of Spring boot executable jar?
The core class that Spring boot uses to support loading inline jars is org.springframework.boot.loader.jar.JarFile (inherited
From Java.util.jar.JarFile). It allows you to from a standard jar file
or inline child jar data to load the jar contents. When first loaded, the location of each jarentry is mapped to a physical file that is offset from the external jar:

The example above shows how to find A.class at 0063 Myapp.jar. The b.class from the inline jar can actually be found at 3452 Myapp.jar, C.class can be found in 3980 places.

4. External configuration

Spring boot can be externally configured using properties files, YAML files, environment variables, command line parameters, and so on. Property values can be injected directly into the bean using @value annotations and accessed through spring's environment abstraction or through @configurationproperties annotations bound to structured objects.
Example:
Yaml Configuration file Contents:

To inject a single attribute using @value annotations:

To inject a property group using @configurationproperties:

5. Embedded Servlet container

Spring Boot's Web module incorporates embedded tomcat, Jetty, and undertow to build a self-contained servlet container. When a web app is packaged into an executable jar package, the corresponding servlet container is also embedded in the app jar. and Servlets, filters and listeners can be registered by the container by declaring them as beans. servlet containers can also be related to custom properties through an external configuration, such as Server.port, Server.session.persistence, and so on.

6. Seamless integration of spring security,spring data, spring message, etc.

Spring boot Imports these dependencies through Stater Pom, and spring boot initiates the corresponding automatic configuration when the relevant jar is found in classpath. For example, if the jar of security is in Classpath, the Spring boot Web app will automatically start the security restrictions and start the basic certification by default.

Development-time features provided by 7.devtools

Spring Boot's Devtools module can add development time features to your application, such as default values for development environment properties, automatic restart, livereload (triggers browser refresh when changes are voluntary), global settings, and so on.

8.Actuator of production characteristics (health,metrics, etc.)

Actuator is a machine term, there is no unified translation, can be translated as an actuator or actuator, actuator through a small change can produce a great move.
Spring Boot Actuator provides some of the necessary features for your application, such as auditing (audit), health, and data Acquisition (metrics). Enables you to manage and monitor your applications over HTTP (requires SPRINGMVC), JMX, and even remote shell (SSH, Telnet) After you deploy the application to the production environment. For example, in an HTTP environment, access the Contexturl/health path to query the current environment's disk space, application and database status, etc., access the Contexturl/metrics path to query the current JVM memory usage, the status of the thread pool, and so on.

V. How to use Spring boot?1. System Requirements

By default, spring Boot 1.3.6.RELEASE requires JAVA7 and spring frames 4.2.7.RELEASE or more. You can use spring Boot under JAVA6, but you need to add additional configuration. The explicitly supported build tools are MAVEN (3.2+) and Gradle (1.12+).
Note: Although you can use spring Boot in a Java6 or Java7 environment, we usually recommend that you use JAVA8 if possible.

2. Inline servlet Container Requirements

The following inline containers support out-of-the-box (out of the box) when they meet the corresponding servlet and JDK version requirements:

name servlet version Java version
Tomcat 8 3.1 java7+
Tomcat 7 3.0 java6+
Jetty 9 3.1 java7+
Jetty 8 3.0 java6+
Undertow 1.1 3.1 java7+

※undertow is a flexible, high-performance WEB server developed in Java that provides non-clogging mechanisms including blocking and NIO-based. Undertow is a red Hat open source product and is the Wildfly default Web server.

You can also deploy the spring boot app to any container that is compatible with servlet 3.0+.

3. Use spring Boot3.1 to run directly on the spring Boot CLI or build on http://start.spring.io/. 3.2 Eclipse uses the Spring Stater Project menu provided by the Spring IDE plug-in.

This method is the same as the Start.spring.io in 3.1.

3.3 Maven's Pom directly inherits Spring-boot-starter-parent.

Spring boot relies on the GroupID for Org.springframework.boot. Usually your maven pom file needs to inherit Spring-boot-starter-parent and then declare one or more "starter POMs" dependencies.
A typical spring boot project's POM file structure is described below:

3.4 Do not use inheritance, use Import

Scope=import allows you to eliminate the need to inherit spring-boot-starter-parent, while preserving the dependency management provided by spring-boot-starter-parent (except for plug-in management):

※ In addition to 3.4, 3.1 to 3.3 of the resulting POM file and project structure is the same.

Vi. what are the shortcomings of Spring boot?


, spring boot does not provide matching features for service discovery and registration (such as the need for Eureka with Spring Cloud and Netflix), and the monitoring capabilities provided by its own actuator also require interfacing with existing monitoring. There is no matching security control scheme, for the rest of the landing, you also need to do the actual URI of the normalization work.
Spring boot as a micro-framework, the implementation of the micro-service is still some distance.

Seven, reference links:

Http://www.infoq.com/cn/articles/microframeworks1-spring-boot?utm_source=infoq_en&utm_medium=link_on_en_ Item&utm_campaign=item_in_other_langs
http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/
http://www.csdn.net/article/a/2016-05-12/15838098

Spring Boot Tutorial-1. Brief 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.