01-Getting started with SpringBoot2

1 System Requirements

  • Java 8 & compatible with java14 .

  • Maven 3.3+

  • idea

1.1 maven settings

<mirrors>
      <mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>central</mirrorOf>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
      </mirror>
  </mirrors>
 
  <profiles>
         <profile>
              <id>jdk-11</id>
              <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>11</jdk>
              </activation>
              <properties>
                <maven.compiler.source>11</maven.compiler.source>
                <maven.compiler.target>11</maven.compiler.target>
                <maven.compiler.compilerVersion>11</maven.compiler.compilerVersion>
              </properties>
         </profile>
  </profiles>

2 HelloWorld

Requirements: Browse send /hello request, respond Hello, Spring Boot 2

2.1 Create maven project

2.2 Introducing dependencies

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


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

    </dependencies>

2.3 Create the main program

/**
 * 主程序类
 * @SpringBootApplication:这是一个SpringBoot应用
 */
@SpringBootApplication
public class MainApplication {
    
    

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

2.4 Writing business

@RestController
public class HelloController {
    
    


    @RequestMapping("/hello")
    public String handle01(){
    
    
        return "Hello, Spring Boot 2!";
    }


}

2.5 Testing

Run the main method directly

2.6 Simplified configuration

application.properties

server.port=8888

2.7 Simplified Deployment

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

Type the project into a jar package and execute it directly on the target server.

Guess you like

Origin blog.csdn.net/m0_46502538/article/details/121773801