Microservice Spring Boot: focus on business logic
1. Microservice Spring Boot
(1) Basic knowledge
1. Advantages:
- Simplify Spring application building and development process
- Remove a lot of XML configuration files
- Simplify complex dependency management
2. Technical basis:
Java 基础、Servlet、JDBC、Maven、Spring、Spring MVC、MyBatis
3. Features:
1. Standalone Spring project
以 jar 包形式独立运行
项目只需通过命令“ java–jar xx.jar” 即可运行
2. Embedded Servlet Container
使用嵌入式 Servlet 容器(Tomcat、Jetty 、 Undertow)
应用无需打成 WAR 包
3. Provide starter to simplify Maven configuration
提供一系列“starter”项目对象模型(POMS)来简化 Maven 配置
4. Provides a lot of automatic configuration
提供大量默认自动配置、简化项目开发
开发人员也通过配置文件修改默认配置
5. Self-contained application monitoring
可对正在运行项目提供监控
6. No code generation and xml configuration
不需要任何 xml 配置即可实现 Spring 的所有配置
(2) Environment Construction
1. Development platform: IntelliJ IDEA
2. Version selection: stable
Spring Boot 2.x
JDK 8.0 及以上版本
Maven 3.x
IntelliJ IDEA 14.0 以上
3. Create a Spring Boot project
1. Create with Maven: Find the tutorial yourself (omitted)
- Dependency file: pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<relativePath/>
</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>
- Main program: helloWorldApplication.java—— @SpringBootApplication
package net.biancheng.www;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class helloWorldApplication {
public static void main(String[] args) {
SpringApplication.run(helloWorldApplication.class, args);
}
}
2. Create with Spring Initializr
Spring 项目创建向导(Spring Initializr )
1 Method 1: Projects → New Project
2 Method 2: File → New → Project → Spring Initializr
问题:https://start.spring.io——去掉https的s
- Web → Spring Web Starter
- Template → Thymeleaf
- SQL → Spring Data JPA → Mysql Driver
Second, third-party library configuration: zero configuration, automatic configuration,
开箱即用(out-of-the-box)