1. Getting started with Spring Boot
1. Introduction to Spring Boot
A framework to simplify Spring application development;
A big integration of the entire Spring technology stack;
One-stop solution for J2EE development;
2. Microservices
Microservices: architectural style (service microization)
An application should be a group of small services; it can communicate with each other via HTTP;
Single application: ALL IN ONE
Microservices: Each functional element is ultimately a software unit that can be independently replaced and independently upgraded;
Refer to the microservice documentation for details
3. Environmental preparation
Environmental constraints
--Jdk1.8: Spring Boot recommends jdk1.7 and above; java version "1.8.0_112"
-Maven3.x: maven 3.3 or above; Apache Maven 3.3.9
–IntelliJIDEA2017:IntelliJ IDEA 2017.2.2 x64、STS
–SpringBoot 1.5.9.RELEASE:1.5.9;
Unified environment
1. MAVEN settings;
Add to the profiles tag of the settings.xml configuration file of maven
<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. IDEA settings
Integrate maven in;
4、Spring Boot HelloWorld
One function:
The browser sends a hello request, the server accepts the request and processes it, and responds with the Hello World string;
1. Create a maven project
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>
3. Write a main program; start the Spring Boot application
/**
* @SpringBootApplication 来标注一个主程序类,说明这是一个Spring Boot应用
*/
@SpringBootApplication
public class HelloWorldMainApplication {
public static void main(String[] args) {
// Spring应用启动起来
SpringApplication.run(HelloWorldMainApplication.class,args);
}
}
4. Write related Controller and Service
@Controller
public class HelloController {
@ResponseBody
@RequestMapping("/hello")
public String hello(){
return "Hello World!";
}
}
5. Run the main program test
6. Simplify deployment
<!-- 这个插件,可以将应用打包成一个可执行的jar包;-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Mark this application into a jar package and execute it directly with the command of java -jar;