微服务Spring Boot:专注业务逻辑
- 一、微服务Spring Boot
- (一)基础知识
- 1、优点:
- 2、技术基础:
- 3、特点:
- 1. 独立运行的 Spring 项目
- 2. 内嵌 Servlet 容器
- 3. 提供 starter 简化 Maven 配置
- 4. 提供大量自动配置
- 5. 自带应用监控
- 6. 无代码生成和 xml 配置
- (二)环境搭建
- 1、开发平台:IntelliJ IDEA
- 2、版本选择:稳定
- 3、创建 Spring Boot 项目
- 1. 使用 Maven 创建:自行查找教程(略)
- 2. 使用 Spring Initializr 创建
- 1 方式1: Projects → New Project
- 2 方式2:File → New → Project → Spring Initializr
- 二、第三方库配置:零配置、自动配置、
一、微服务Spring Boot
(一)基础知识
1、优点:
- 简化 Spring 应用搭建和开发过程
- 去除大量 XML 配置文件
- 简化复杂依赖管理
2、技术基础:
Java 基础、Servlet、JDBC、Maven、Spring、Spring MVC、MyBatis
3、特点:
1. 独立运行的 Spring 项目
以 jar 包形式独立运行
项目只需通过命令“ java–jar xx.jar” 即可运行
2. 内嵌 Servlet 容器
使用嵌入式 Servlet 容器(Tomcat、Jetty 、 Undertow)
应用无需打成 WAR 包
3. 提供 starter 简化 Maven 配置
提供一系列“starter”项目对象模型(POMS)来简化 Maven 配置
4. 提供大量自动配置
提供大量默认自动配置、简化项目开发
开发人员也通过配置文件修改默认配置
5. 自带应用监控
可对正在运行项目提供监控
6. 无代码生成和 xml 配置
不需要任何 xml 配置即可实现 Spring 的所有配置
(二)环境搭建
1、开发平台:IntelliJ IDEA
2、版本选择:稳定
Spring Boot 2.x
JDK 8.0 及以上版本
Maven 3.x
IntelliJ IDEA 14.0 以上
3、创建 Spring Boot 项目
1. 使用 Maven 创建:自行查找教程(略)
- 依赖文件:pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
</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>
- 主程序: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. 使用 Spring Initializr 创建
Spring 项目创建向导(Spring Initializr )
1 方式1: Projects → New Project
2 方式2:File → New → Project → Spring Initializr
问题:https://start.spring.io——去掉https的s
- Web → Spring Web Starter
- Template → Thymeleaf
- SQL → Spring Data JPA → Mysql Driver
二、第三方库配置:零配置、自动配置、
开箱即用(out-of-the-box)