1. Preparing the Environment
- 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 set: to profiles of the label maven settings.xml configuration file to add
<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>
2. To achieve SpringBoot Helloworld Case
Hello browser sends a request, the server accepts and processes the request, response Hello World string;
2.1, create a maven project; (jar)
2.2, introducing 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>
3, write a main program; launch applications Spring Boot
package com.xdr;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/*
@SpringBootApplication 来标注一个主程序
*/
@SpringBootApplication
public class HelloWorldApplication {
public static void main(String[] args) {
System.out.println("启动springboot程序");
SpringApplication.run(HelloWorldApplication.class, args);
}
}
4, related to the preparation Controller, 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(){
return "Hello SpringBoot";
}
}
5, the main program to run test
Create a file written in the resource application.properties
server.port=8082
The port number was changed to 8082, so as not to conflict with the 8080
Access Project
6, simplified deployment
<!-- 这个插件,可以将应用打包成一个可执行的jar包;-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
This application will be labeled jar package, the direct use of java -jar xxx.jar (xxx represents the name of the jar package) command execution;
comes packaged in Maven idea
Refresh Project: