Spring Boot learning the basics (a)

This article is introduced for spring boot in very shallow knowledge, do not understand, just contact surface, some of the more complex content is not too much description. The text of the error, please keep, thank you ~

A, Spring Boot Profile

Before introducing the Spring Boot, you must first understand what is Spring.

Spring is a layered Java SE / EE lightweight open source application framework for full-stack to IoC (Inverse Of Control: inversion control) and AOP (Aspect Oriented Programming: Oriented Programming) as a core, a Spring MVC presentation layer and a large number of enterprise applications JDBC technology and business transaction management layer persistence layer Spring, but also the integration of the open source world many well-known third-party frameworks and libraries.

springUnlike a general framework, which is a polymeric framework, enables Java developers to be more convenient by spring framework and systematic. Another major use of the Java web development isSpring Framework

spring bootSpring is extended, eliminating the Spring application to set the desired XML configuration, also embedded tomcat and so on, so that developers easier.

Two, Spring Boot features and core functionality

(1) spring boot features
  • For the development of Spring-based experience to provide faster entry
  • Out of the box, there is no code generation, need not XML configuration. But you can also modify the default values ​​to meet specific needs
  • It provides a number of large projects in common non-functional properties, such as embedded servers, security, index, health monitoring, external configuration, etc.
  • SpringBoot not to enhance the functionality of Spring, but provides a way to quickly use the Spring
(2) spring boot of the core functions
  • Starting rely
    starting rely essentially a Maven project object model (Project Object Model, POM), defines the transitive dependencies on other libraries, these things together which is to support a function.
  • Auto Configuration
    automatically configures Spring Boot is a run-time (more accurately, when the application starts) process, taking into account many factors before deciding which should be used to configure Spring, which should not be used. This process is done automatically in the Spring.

Third, the simple use of spring boot

(1) Create a new maven project (can also be directly spring initializr new project, so there is no need to do some preparatory work, such as the number of import dependence, where the new project is to better understand the maven spring boot, the actual development of new direct spring initializr project like), and import-related dependence (note the version in pom.xml file)

<!--添加起步依赖-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
    </parent>

    <!--添加web的启动依赖-->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

(2) create a spring boot startup class

@SpringBootApplication
public class MySpringBootApplication {

    public static void main(String[] args) {

        SpringApplication.run(MySpringBootApplication.class, args);
    }
}

It should be noted that == @ SpringBootApplicationIs an== annotations, not expand described herein, annotations can be understood as plain label, the label can be reduced by this configuration and complete the corresponding function.

(3) class to start running spring boot
console appears in the figure below the red box the words to explain to run a successful
Here Insert Picture Description
addition results also appeared tomcat, description spring boot is built in the tomcat.
In the browser, enter localhost: 8080 , you can visit the following page
Here Insert Picture Description

Four, spring boot configuration files

spring boot is based on the contract, so a lot of configuration has a default value, spring boot default configuration file must be, and can only be application or application-xxx named yml files or properties files, to change the default configuration accordingly ( create a) modify the configuration file.
In addition spring boot is loaded by default application.properties or application.yml (application.yaml) files from the resources directory.

  • application.properties file
    .propertiesFile is in the form of key-value pairs, the general format iskey=value

  • application.yml file
    .yml/.yamlFile format is prepared YAML (YAML Aint Markup Language) file format, is an intuitive YAML can be recognized by the computer of the data sequence format, and easily read humans.
    Its general form iskey: value(Note value preceded by a space)

Specific configuration See the official documentation .

Here Insert Picture Description
2020.03.07

Published 52 original articles · won praise 59 · views 6815

Guess you like

Origin blog.csdn.net/ataraxy_/article/details/104702350