1. Environment preparation
- The JDK: 1.8
- Apache Maven: 3.6.1
- IntelliJ IDEA 2019.1.3 x64
- SpringBoot 1.5.9.RELEASE: 1.5.9;
1.1. MAVEN Settings: Add the Profiles tag to MAVEN’s settings. XML configuration file
<profile>
<id>JDK - 1.8 -</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
Copy the code
2. Implement SpringBoot Helloworld case
The browser sends a Hello request, the server accepts and processes the request, and responds with a Hello World string.
2.1. Create a Maven project; (jar)
2.2 import Spring Boot-related dependencies
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9. RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
Copy the code
3. Write a main program; Start the Spring Boot application
package com.xdr;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/* @springBootApplication to annotate a main program */
@SpringBootApplication
public class HelloWorldApplication {
public static void main(String[] args) {
System.out.println("Start the Springboot program"); SpringApplication.run(HelloWorldApplication.class, args); }}Copy the code
4. Write related Controller and Service
package com.xdr.com.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class Controller {
@RequestMapping("hello")
public String sayHello(a){
return "Hello SpringBoot"; }}Copy the code
5. Run the main program test
Create the application.properties file write under resource
server.port=8082
Copy the code
Change the port number to 8082 to avoid conflicts with 8080
Access to the project
Simplify deployment
<! -- This plugin can package the application into an executable JAR package; -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Copy the code
Jar the application into a jar package, directly using the java-jar xxx.jar command (XXX indicates the name of the jar package) to execute;
Maven package comes with IDEA
Refresh items: