Springboot2.x environment dependencies

  • The JDK version is jdK8 or older, because springBoot is based on Spring.framework5, so springBoot2 needs to use JDK8 or older

  • Maven3.2 or later is required. Download address: maven.apache.org/download.cg…

  • Personal use of the development tool is IntelliJ IDEA, the reason is quite simple IDEA internal integration of Springboot environment rapid building tool Spring Initializr. IDEA website: www.jetbrains.com/idea/

Manually create a Spring Boot2-based Web service

  1. Create a Maven project with an IDEA as an example

    So the directory looks like this

  2. Example Modify poM files

    <? The 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" > The < modelVersion > 4.0.0 < / modelVersion > < groupId > 1.0 < / groupId > < artifactId > 1.1 < / artifactId > < version > 1.0 - the SNAPSHOT < / version > <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.3.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> </project>Copy the code
  3. Create a Java file in the Java folder

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    @Controller
    @EnableAutoConfiguration
    @ResponseBody
    public class SpringBootStart {
        @RequestMapping("/")
        public String index(){
            return "Hello SpringBoot!";
        }
    
        public static void main(String[] args) {
            SpringApplication.run(SpringBootStart.class, args);
        }
    }
    Copy the code
  4. Then run the main method

  5. Open your browser and enter http://localhost:8080/ in the address box

Now manually create springboot project successfully run!

Use tools to create a SpringBoot project

Springboot Initializr is a tool provided by Spring to create springboot projects. It is available at start.spring. IO /

Maven version dependencies for SpringBoot

The content of the pom. XML file in Springboot is very small. We usually need to configure a large number of versions in the pom. XML file in a project.

In fact, if you hold down CTRL in the developer and click inside, springBoot already has some default dependencies configured. If you don’t, SpringBoot will use some of its own default dependencies.