001 SringBoot study notes

1. The original analysis of the advantages and disadvantages Spring

(1) Advantages

 

  Spring is Java Enterprise Edition (Java Enterprise Edition, JEE, also known as J2EE) lightweight substitute. Without developing heavyweight Enterprise JavaBean (EJB), Spring provides a relatively simple method for enterprise Java development, through dependency injection and aspect-oriented programming , using simple Java objects (Plain Old Java Object, POJO) implements EJB function.
(2) disadvantages

  Although the Spring component code is lightweight, but its configuration is heavyweight . A beginning, Spring configuration using XML, but also a lot of XML configuration. Spring 2.5 introduces a component scans based annotation, which eliminates a lot for the explicit XML configuration components of the application itself. Spring 3.0 introduces Java-based configuration, which is a type-safe reconfigurable configuration, you can replace XML.
  All of these configurations represent a loss during development. Because thinking about Spring features and solutions need to be configured to switch between thinking business problems, so write configuration crowding out the time to write application logic. And all frameworks, Spring and practical, but at the same time it requires a lot of rewards.
  In addition, dependency management project is a time-consuming and labor-intensive thing . When setting up the environment, you need to analyze the coordinates of which library you want to import, but also need to analyze coordinate with other libraries have import dependency, dependent upon the wrong version, followed by incompatibility issues will seriously hamper the development progress of the project.

2.SpringBoot Overview

(1) disadvantage of SpringBoot solve the above-Spring

  SpringBoot to improve and optimize the disadvantage of the Spring carried out, based on convention over configuration idea, allowing developers do not have to switch between thinking in configuration and business logic, threw himself into writing code business logic, thereby greatly improving the efficiency of development, shorten the project cycle to some extent.

(2) SpringBoot Characteristics

  <1> Spring-based development for faster entry experience
  <2> Out of the box, no code generation, and without XML configuration. But can also modify the default values to meet the specific needs of
  <3> provides a number of large projects of common non-functional characteristics, such as embedded servers, security, index, health monitoring, configuration and other external
  <3> SpringBoot not function for Spring enhanced on, but to provide a way to quickly use the Spring

(3) SpringBoot core functionality

<1> starting rely
starting rely essentially is 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.
Simply put, the initial reliance is to have some kind of function to coordinate packaged together and provide some default function .

<2> Automatic 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.

3.SpringBoot Quick Start

(1) create a Maven project

 

Create a maven project idea to use tool that works for ordinary java project can be (without the use of skeleton, has been the next step on the line).

(2) adding SpringBoot start dependent

<1> SpringBoot claim project to inherit SpringBoot start dependent spring-boot-starter-parent

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.RELEASE</version>
    </parent>

<2> SpringBoot SpringMVC developed to integrate the Controller, the web of items to import-dependent promoter

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

At this pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<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>lucky</groupId>
    <artifactId>springboot</artifactId>
    <version>1.0-SNAPSHOT</ Version > 

    <-! All springBoot project must inherit-the Boot-Starter-the Spring parent -> 
    < parent > 
        < groupId > org.springframework.boot </ groupId > 
        < artifactId > the Spring-the Boot-Starter-parent </ artifactId > 
        < Version > 2.0.1.RELEASE </ Version > 
    </ parent > 

    < the Dependencies > 
        <-! start a web project is dependent -> 
        < dependency > 
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>


</project>

(3) preparation of bootstrap class SpringBoot

To guide the class started SpringBoot provided by SpringBoot can be accessed

MySpringBootApplication.java

Package Lucky; 

Import org.springframework.boot.SpringApplication;
 Import org.springframework.boot.autoconfigure.SpringBootApplication; 

// declare a class is class springboot guide 
@SpringBootApplication
 public  class MySpringBootApplication {
     public  static  void main (String [] args) {
         // rUN method: bootstrap class of operation springBoot, run bytecode object parameter is the class of the guide springBoot 
        SpringApplication.run (MySpringBootApplication. class ); 
    } 
}

(4) write controller class

package lucky.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(path = "/quick")
public class QuickController {

    @RequestMapping(path = "/hello")
    @ResponseBody
    public String hello(){
        return "hello springBoot";
    }
}

(5) test results

Print Console:

Browser to access the results:

4.SpringBoot hot deployment

 

  We repeated changes in development classes, and other resources page, after each modification is need to restart to take effect, so every time you start a hassle , wasting a lot of time, we may not be able to restart the entry into force of the revised Code, add the following configuration in pom.xml can achieve this function, we call hot deployment .

      <! - Thermal deployment configuration -> 
        < dependency > 
            < the groupId > org.springframework.boot </ the groupId > 
            < the artifactId > Spring-Boot-DevTools </ the artifactId > 
            <! - optional = to true, does not rely on passing, the project relies devtools; dependent on project after project myboot If you want to use devtools, need to re-introduce -> 
            < optional > to true </ optional > 
        </ dependency >

Note: IDEA were SpringBoot hot deploy reasons for failure:

This happens, not hot deployment configuration issues, the fundamental reason is because Intellij IEDA not automatically compile the case, the need for IDEA automatically compile default settings, as follows:

Then Shift + Ctrl + Alt + /, Select Registry

5.IDEA quickly create project SpringBoot

Project results:

 

Guess you like

Origin www.cnblogs.com/luckyplj/p/11434023.html
001