Java - Spring Boot entry

1 Introduction

spring Boot is to simplify java development process and build, even with springMVC framework, it still requires a lot of configuration and rely on import,
this is cumbersome, spring Boot uses the "habit due to the configuration" principle, be a key technology deployment, which greatly reduces the amount of artificial development.

 

Traditional Spring development process:

 

 

 Spring Boot development process:

 

 

 Spring Boot in dependency management, container configuration, component parameters in this area, are greatly optimized development capacity.
Developers only need to focus on business logic development.

 

2. Construction of the project

1) Create a directory and dependencies introduced

spring directory structure:

 

 

 Create a project:

 

 

 The introduction of project dependencies:

<parent>
    <groupId>org.springframework.boot</groupId>
    <!--所有spring都要依赖spring-boot-parent才能进行构建-->
    <artifactId>spring-boot-parent</artifactId>
    <version>2.0.1.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <!--Use a series starter starter to describe the engineering features you need -> 
        < artifactId > the Spring-the Boot-starter-Web </ artifactId > 
    </ dependency > 
</ the Dependencies > 
<-! Project build mode -> 
< Build > 
    <! - in the form of plug-ins to be constructed -> 
    < plugins > 
        < plugin > 
            < the groupId > org.springframework.boot </ the groupId > 
            <! - package all the classes and resources into a separate jar package - -> 
            < the artifactId >spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

SpringBoot will help us introduce a range of dependencies:

 

 

 

2) built with Maven Spring Boot

(1) Create a Controller

@Controller
public class MyController {
    @RequestMapping("/out")
    @ResponseBody
    public String out(){
        return "success";
    }
}

 

(2) the preparation of the inlet class

Entrance class name: Project name + application word

// Description This is a class entry SpringBoot application 
@SpringBootApplication
 public  class MySpringBootApplication {
     public  static  void main (String [] args) {
         // Start SpringBoot application 
        SpringApplication.run (MySpringBootApplication. Class ); 
    } 
}

This start-up mode and the python django and go in the beego resembled.

(3) application launch

Entrance to perform file:

 

 

 springboot start up.

 

 

 Access browser:

 

 

 springboot application, deployment, steps have been made to start up.

Is not particularly easy, no longer have to use a tomcat to start the application.

 

3) Spring Initializr build applications springboot

When using a manually created Maven, you need to build the project structure, dependencies introduced manually, creating class entry.
IDEA provides a wizard tool Initizlizr, we can help create a key SpringBoot project.

 

 

 

 Project Configuration:

 

 

 Select starters:

 

 

 

 Once created, we find that automatically help us generate a variety of configuration files.
Entry automatically generated categories:

@SpringBootApplication
public class Springbootdemo1Application {
    public static void main(String[] args) {
        SpringApplication.run(Springbootdemo1Application.class, args);
    }
}

 

Guess you like

Origin www.cnblogs.com/yangmingxianshen/p/12521628.html