1. Quickly build Springboot applications

1. Basic Concepts

The emergence of Spring is a boon for enterprise-level applications, which makes enterprise-level application development easier. But as Spring has grown, it has slowly become heavier and heavier. Even though the maven tool produced by apache can make project creation and management easier, there is still a burden for developers:

1) Have to deal with configuration files such as xml;

2) It is not allowed to supplement various dependent packages;

And the authors of Spring realized this, so Springboot appeared.

The significance of Springboot is to quickly create and run an application . If we needed ten minutes to create a simple spring project, now we can create a springboot application in just ten seconds.

 

2. Environment

At the time of writing this article, the stable version of springboot is: 2.0.1;

it needs:

1) JDK1.8 ;

2) maven3.2+ or gradle4+;

Development tools use:

1)intellij IDEA;

2) Spring tool suite(STS); 

 

3. Build Spring applications

1) Open the IDEA development tool, with the STS suite by default;

2) new -> project -> Spring Initializer -> next -> fill in the project information -> check web -> fill in the project name and path -> finish

When maven has finished processing, a simple Springboot project has been built.

 

4. Test

We write a controller under the classpath

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SampleController {

    @RequestMapping(value = "hello")
    public String hello(){
        return "Hello World";
    }
}

Run the main method to start the program

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

@SpringBootApplication
public class SpringbootApplication {

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

As you can see on the console, we successfully run tomcat on port 8080 (Note: springboot has built-in tomcat, we do not need to configure the local tomcat)

Tomcat started on port(s): 8080 (http) with context path ''
2018-04-14 22:06:26.584  INFO 16752 --- [main] cn.lay.SpringbootApplication: Started SpringbootApplication in 6.587 seconds (JVM running for 8.949)

Type in the browser

http://localhost:8080/hello

show

Hello World

A simple springboot based web application is done

Guess you like

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