Spring Boot (1) Simple Getting Started

1.  What is Spring Boot

 

2.  Advantages and disadvantages of Spring Boot

 

3.  Quick Start

3.1.  Set the parent of spring boot

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

Note: The Spring boot project must set the parent to the spring boot parent  , which contains a large number of default configurations, which greatly simplifies our development.

3.2.  Import the web support of spring boot

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

3.3.  Add Spring boot plugin

<plugin>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

3.4.  Writing the first Spring Boot application

@Controller
@SpringBootApplication
@Configuration
public class HelloApplication {
    
    @RequestMapping("hello")
    @ResponseBody
    public String hello(){
        return "hello world!";
    }
    
    public static void main(String[] args) {
        SpringApplication.run(HelloApplication.class, args);
    }

}

Code description:

1. @SpringBootApplication : The core annotation of the Spring Boot project, the main purpose is to enable automatic configuration. ;

2. @Configuration : This is a configuration class that configures Spring ;

3. @Controller : Indicates that this is a SpringMVC Controller ;

4. main method: start an application in the main method , that is: the entry of this application;

3.5.  Start the application

In a Spring Boot project, there are two ways to start, one is to run  Java Application directly, and the other is to run through Spring Boot 's Maven plugin.

The first:

 

Start effect:

If you see the following information, the startup is successful:

INFO 6188 --- [           main] c.i.springboot.demo.HelloApplication     : Started HelloApplication in 3.281 seconds (JVM running for 3.601)

3.6.  Testing

Open a browser and enter the address:


Effect:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325994567&siteId=291194637