@@ -1,9 +1,10 @@ | |||
## spring-boot-demo-springdoc | |||
# spring-boot-demo-springdoc | |||
> 此 demo 主要演示了 Spring Boot 如何通过 Springdoc 集成 swagger | |||
### 1.开发步骤 | |||
#### 1.1.添加依赖 | |||
## 1.开发步骤 | |||
### 1.1.添加依赖 | |||
> 3.0.0-M4 依赖的 servlet 为 jakarta,目前 release 的 Springdoc 依赖的是 javax.servlet-api,需要同时使用最新的 2.0.0-M5 | |||
@@ -39,7 +40,7 @@ | |||
</dependencies> | |||
``` | |||
#### 1.2.编写测试接口 | |||
### 1.2.编写测试接口 | |||
```java | |||
@Slf4j | |||
@@ -113,7 +114,7 @@ public class UserController { | |||
``` | |||
#### 1.3.编写返回对象 | |||
### 1.3.编写返回对象 | |||
```java | |||
@Data | |||
@@ -141,7 +142,7 @@ public class User implements Serializable { | |||
} | |||
``` | |||
#### 1.4.配置 Springdoc | |||
### 1.4.配置 Springdoc | |||
- **SpringdocAutoConfiguration** | |||
@@ -169,11 +170,11 @@ springdoc: | |||
packages-to-scan: com.xkcoding.swagger.controller | |||
``` | |||
### 2.测试 | |||
## 2.测试 | |||
启动项目,访问地址:http://localhost:8080/demo/swagger-ui/index.html | |||
### 3.参考 | |||
## 3.参考 | |||
- [Springdoc 官方文档](https://springdoc.org/) | |||
- [Springfox 迁移到 Springdoc 步骤](https://springdoc.org/#migrating-from-springfox) |
@@ -1,10 +1,10 @@ | |||
## spring-boot-demo-async | |||
# spring-boot-demo-async | |||
> 此 demo 主要演示了 Spring Boot 如何使用原生提供的异步任务支持,实现异步执行任务。 | |||
### 1.开发步骤 | |||
## 1.开发步骤 | |||
#### 1.1.添加依赖 | |||
### 1.1.添加依赖 | |||
```xml | |||
<dependencies> | |||
@@ -27,7 +27,7 @@ | |||
</dependencies> | |||
``` | |||
#### 1.2.增加异步线程池的配置 | |||
### 1.2.增加异步线程池的配置 | |||
> 注意:如果不配置的话,会使用默认的线程池配置 | |||
@@ -50,7 +50,7 @@ spring: | |||
thread-name-prefix: async-task- | |||
``` | |||
#### 1.3.同步、异步任务模拟 | |||
### 1.3.同步、异步任务模拟 | |||
> 1. 异步方法的返回值,需要指定为:`java.util.concurrent.Future`,`org.springframework.util.concurrent.ListenableFuture`,`java.util.concurrent.CompletableFuture` | |||
> 2. 方法上标记 `@Async` | |||
@@ -116,7 +116,7 @@ public class MockTaskFactory { | |||
} | |||
``` | |||
#### 1.4.在启动类上增加注解 `@EnableAsync` | |||
### 1.4.在启动类上增加注解 `@EnableAsync` | |||
```java | |||
@EnableAsync | |||
@@ -130,9 +130,9 @@ public class AsyncApplication { | |||
} | |||
``` | |||
### 2.测试 | |||
## 2.测试 | |||
#### 2.1.编写测试代码 | |||
### 2.1.编写测试代码 | |||
```java | |||
@Slf4j | |||
@@ -178,7 +178,7 @@ public class MockTaskFactoryTest { | |||
} | |||
``` | |||
#### 2.2运行结果 | |||
### 2.2运行结果 | |||
运行 `MockTaskFactoryTest`,查看日志 | |||
@@ -206,6 +206,6 @@ INFO 11574 --- [ main] com.xkcoding.async.task.MockTaskFactory : task | |||
INFO 11574 --- [ main] c.x.async.task.MockTaskFactoryTest : 同步任务全部执行结束,总耗时:10032 毫秒 | |||
``` | |||
### 3.参考 | |||
## 3.参考 | |||
- [Spring Boot 官方文档之异步任务线程池的配置](https://docs.spring.io/spring-boot/docs/3.0.0-M4/reference/htmlsingle/#features.task-execution-and-scheduling) |
@@ -1,10 +1,10 @@ | |||
## spring-boot-demo-email | |||
# spring-boot-demo-email | |||
> 此 demo 主要演示了 Spring Boot 如何整合邮件功能,包括发送简单文本邮件、HTML邮件(包括模板HTML邮件)、附件邮件、静态资源邮件。 | |||
### 1.开发步骤 | |||
## 1.开发步骤 | |||
#### 1.1.添加依赖 | |||
### 1.1.添加依赖 | |||
```xml | |||
@@ -41,7 +41,7 @@ | |||
</dependencies> | |||
``` | |||
#### 1.2.添加邮件相关配置 | |||
### 1.2.添加邮件相关配置 | |||
```yaml | |||
spring: | |||
@@ -67,7 +67,7 @@ jasypt: | |||
password: spring-boot-demo | |||
``` | |||
#### 1.3.编写发送邮件代码 | |||
### 1.3.编写发送邮件代码 | |||
- **抽象邮件服务接口**,方便后期替换不同的客户端实现 | |||
@@ -240,7 +240,7 @@ public class MailServiceImpl implements MailService { | |||
- 其他资源文件参考 `classpath://resources` 目录 | |||
### 2.测试 | |||
## 2.测试 | |||
参考 `MailServiceTest` 测试用例,分别运行各个方法,进行邮件测试 | |||
> 注意: | |||
@@ -248,7 +248,7 @@ public class MailServiceImpl implements MailService { | |||
> 2. **强烈建议各位同学测试的时候,把邮箱改成自己的邮箱进行测试,这样才能实际体会到收到的邮件内容** | |||
> 3. 请勿将 `spring-boot-demo@xkcoding.com` 的邮箱用于发送违法内容,否则作者将收回邮箱权限,同时提交给公安依法追究 | |||
### 3.参考 | |||
## 3.参考 | |||
- [Spring Boot 官方文档之邮件](https://docs.spring.io/spring-boot/docs/3.0.0-M4/reference/htmlsingle/#io.email) | |||
- [Spring 官方文档之邮件](https://docs.spring.io/spring-framework/docs/6.0.0-M5/reference/html/integration.html#mail) | |||
@@ -1,10 +1,10 @@ | |||
## spring-boot-demo-exception-handler | |||
# spring-boot-demo-exception-handler | |||
> 此 demo 演示了如何在Spring Boot中进行统一的异常处理,包括了两种方式的处理:第一种对常见API形式的接口进行异常处理,统一封装返回格式;第二种是对模板页面请求的异常处理,统一处理错误页面。 | |||
### 1.开发步骤 | |||
## 1.开发步骤 | |||
#### 1.1.添加依赖 | |||
### 1.1.添加依赖 | |||
```xml | |||
<dependencies> | |||
@@ -38,7 +38,7 @@ | |||
</dependencies> | |||
``` | |||
#### 1.2.构造JSON异常和页面跳转异常 | |||
### 1.2.构造JSON异常和页面跳转异常 | |||
```java | |||
// JSON 异常 | |||
@@ -68,7 +68,8 @@ public class PageException extends CommonBizException { | |||
} | |||
``` | |||
#### 1.3.异常拦截 | |||
### 1.3.异常拦截 | |||
```java | |||
@Slf4j | |||
@ControllerAdvice | |||
@@ -105,7 +106,7 @@ public class DemoExceptionHandler { | |||
} | |||
``` | |||
#### 1.4.编写统一错误页面 | |||
### 1.4.编写统一错误页面 | |||
> 位于 `src/main/resources/template` 目录下 | |||
@@ -123,9 +124,9 @@ public class DemoExceptionHandler { | |||
</html> | |||
``` | |||
### 2.测试 | |||
## 2.测试 | |||
#### 2.1.编写测试路由代码模拟异常 | |||
### 2.1.编写测试路由代码模拟异常 | |||
```java | |||
@Controller | |||
@@ -1,10 +1,11 @@ | |||
## spring-boot-demo-helloworld | |||
# spring-boot-demo-helloworld | |||
> 本 demo 演示如何使用 Spring Boot 写一个hello world | |||
### 1.开发步骤 | |||
## 1.开发步骤 | |||
### 1.1.添加依赖 | |||
#### 1.1.添加依赖 | |||
```xml | |||
<dependencies> | |||
<dependency> | |||
@@ -25,7 +26,7 @@ | |||
</dependencies> | |||
``` | |||
#### 1.2.启动类 HelloworldApplication.java | |||
### 1.2.启动类 HelloworldApplication.java | |||
```java | |||
@SpringBootApplication | |||
@@ -52,7 +53,7 @@ public class HelloworldApplication { | |||
} | |||
``` | |||
#### 1.3.配置文件 application.yml | |||
### 1.3.配置文件 application.yml | |||
```yaml | |||
server: | |||
@@ -60,7 +61,7 @@ server: | |||
servlet: | |||
context-path: /demo | |||
``` | |||
### 2.测试 | |||
## 2.测试 | |||
启动 `HelloworldApplication` 打开任意浏览器: | |||
- 输入 `http://localhost:8080/demo/hello` ,输出 `Hello, World!`; | |||
@@ -1,9 +1,10 @@ | |||
## spring-boot-demo-properties | |||
# spring-boot-demo-properties | |||
> 本 demo 演示如何获取配置文件的自定义配置,以及如何多环境下的配置文件信息的获取 | |||
### 1.开发步骤 | |||
#### 1.1.添加依赖 | |||
## 1.开发步骤 | |||
### 1.1.添加依赖 | |||
```xml | |||
<dependencies> | |||
@@ -42,7 +43,7 @@ | |||
</dependencies> | |||
``` | |||
#### 1.2.配置类 | |||
### 1.2.配置类 | |||
> 分别使用两种方式获取配置 | |||
@@ -66,7 +67,7 @@ public class DeveloperProperty { | |||
} | |||
``` | |||
#### 1.3.测试入口 | |||
### 1.3.测试入口 | |||
```java | |||
@RestController | |||
@@ -87,7 +88,8 @@ public class PropertyController { | |||
} | |||
``` | |||
#### 1.4.配置文件 | |||
### 1.4.配置文件 | |||
**application.yml** | |||
```yml | |||
server: | |||
@@ -119,13 +121,13 @@ developer: | |||
email: prod环境 237497819@qq.com | |||
``` | |||
#### 1.5.其他 | |||
### 1.5.其他 | |||
编写配置提示,`additional-spring-configuration-metadata.json` | |||
参考: src/main/resources/META-INF/additional-spring-configuration-metadata.json | |||
### 2.测试 | |||
## 2.测试 | |||
1. 启动 `PropertiesApplication` ; | |||
2. 打开任意浏览器,输入 `http://localhost:8080/demo/property` ,检查输出结果; | |||
@@ -1,4 +1,4 @@ | |||
## spring-boot-demo-cache-redis | |||
# spring-boot-demo-cache-redis | |||
> 此 demo 主要演示了 Spring Boot 如何整合 redis,操作redis中的数据,并使用redis缓存数据。连接池使用 Lettuce。 | |||
@@ -184,13 +184,13 @@ $ docker compose -f docker-compose.env.yml up | |||
### 2.2.测试 Redis 基础功能 | |||
> 主要测试使用 `RedisTemplate` 操作 `Redis` 中的数据,查看是否正常序列化: | |||
> | |||
> - opsForValue:对应 String(字符串) | |||
> - opsForZSet:对应 ZSet(有序集合) | |||
> - opsForHash:对应 Hash(哈希) | |||
> - opsForList:对应 List(列表) | |||
> - opsForSet:对应 Set(集合) | |||
> - opsForGeo:** 对应 GEO(地理位置) | |||
- opsForValue:对应 String(字符串) | |||
- opsForZSet:对应 ZSet(有序集合) | |||
- opsForHash:对应 Hash(哈希) | |||
- opsForList:对应 List(列表) | |||
- opsForSet:对应 Set(集合) | |||
- opsForGeo:** 对应 GEO(地理位置) | |||
```java | |||
@Slf4j | |||
@@ -1,4 +1,4 @@ | |||
## spring-boot-demo-distributed-lock-curator | |||
# spring-boot-demo-distributed-lock-curator | |||
> 此 demo 主要演示了 Spring Boot 如何基于 Curator 实现一个分布式锁 | |||
@@ -1,4 +1,4 @@ | |||
## spring-boot-demo-distributed-lock-redis | |||
# spring-boot-demo-distributed-lock-redis | |||
> 此 demo 主要演示了 Spring Boot 如何基于 RedisTemplate 实现一个分布式锁,支持集群部署、支持可重入、支持自动续期等功能 | |||
@@ -1,4 +1,4 @@ | |||
## spring-boot-demo-distributed-lock-redisson | |||
# spring-boot-demo-distributed-lock-redisson | |||
> 此 demo 主要演示了 Spring Boot 如何基于 Redisson 实现一个分布式锁 | |||
@@ -1,4 +1,4 @@ | |||
## spring-boot-demo-distributed-lock-zookeeper | |||
# spring-boot-demo-distributed-lock-zookeeper | |||
> 此 demo 主要演示了 Spring Boot 如何基于 Zookeeper 原生客户端实现一个分布式锁,支持可重入 | |||
@@ -1,10 +1,10 @@ | |||
## spring-boot-demo-log-aop | |||
# spring-boot-demo-log-aop | |||
> 此 demo 主要是演示如何使用 aop 切面对请求进行日志记录,并且记录 UserAgent 信息。 | |||
### 1.开发步骤 | |||
## 1.开发步骤 | |||
#### 1.1.添加依赖 | |||
### 1.1.添加依赖 | |||
```xml | |||
<dependencies> | |||
@@ -44,7 +44,7 @@ | |||
</dependencies> | |||
``` | |||
#### 1.2.添加切面拦截 | |||
### 1.2.添加切面拦截 | |||
```java | |||
@Slf4j | |||
@@ -156,9 +156,10 @@ public class AopLog { | |||
} | |||
``` | |||
### 2.测试 | |||
## 2.测试 | |||
### 2.1.添加测试接口 | |||
#### 2.1.添加测试接口 | |||
```java | |||
@Slf4j | |||
@RestController | |||
@@ -1,9 +1,10 @@ | |||
## spring-boot-demo-logback | |||
# spring-boot-demo-logback | |||
> 此 demo 主要演示了如何使用 logback 记录程序运行过程中的日志,以及如何配置 logback,可以同时生成控制台日志和文件日志记录,文件日志以日期和大小进行拆分生成。 | |||
### 1.开发步骤 | |||
#### 1.1.添加依赖 | |||
## 1.开发步骤 | |||
### 1.1.添加依赖 | |||
```xml | |||
<dependencies> | |||
@@ -28,7 +29,7 @@ | |||
</dependencies> | |||
``` | |||
#### 1.2.编写日志配置文件 | |||
### 1.2.编写日志配置文件 | |||
> 在 `classpath` 下创建名为 `logback-spring.xml` 的配置文件 | |||
@@ -115,7 +116,8 @@ | |||
</configuration> | |||
``` | |||
#### 1.3.添加日志打印 | |||
### 1.3.添加日志打印 | |||
```java | |||
@Slf4j | |||
@SpringBootApplication | |||
@@ -139,7 +141,7 @@ public class LogbackApplication { | |||
} | |||
``` | |||
### 2.测试 | |||
## 2.测试 | |||
运行 `LogbackApplication` | |||
@@ -147,6 +149,6 @@ public class LogbackApplication { | |||
- `logs/demo-log/demo-log-logback/info.created_on_xxxx.log` | |||
- `logs/demo-log/demo-log-logback/error.created_on_xxxx.log` | |||
### 3.参考 | |||
## 3.参考 | |||
- [Spring Boot 官方文档之 Logging 配置](https://docs.spring.io/spring-boot/docs/3.0.0-M4/reference/htmlsingle/#howto.logging) |
@@ -1,10 +1,10 @@ | |||
## spring-boot-demo-actuator | |||
# spring-boot-demo-actuator | |||
> 本 demo 主要演示了如何在 Spring Boot 中通过 actuator 检查项目运行情况 | |||
### 1.开发步骤 | |||
## 1.开发步骤 | |||
#### 1.1.添加依赖 | |||
### 1.1.添加依赖 | |||
```xml | |||
<dependencies> | |||
@@ -36,7 +36,7 @@ | |||
</dependencies> | |||
``` | |||
#### 1.2.配置文件 application.yml | |||
### 1.2.配置文件 application.yml | |||
```yaml | |||
server: | |||
@@ -65,14 +65,14 @@ management: | |||
include: '*' | |||
``` | |||
### 2.测试 | |||
## 2.测试 | |||
启动 `ActuatorApplication` ,会在**控制台**里查看所有可以访问的端口信息 | |||
1. 打开浏览器,访问:http://localhost:8090/sys/actuator/mappings ,输入用户名(xkcoding)密码(123456)即可看到所有的mapping信息 | |||
2. 访问:http://localhost:8090/sys/actuator/beans ,输入用户名(xkcoding)密码(123456)即可看到所有 Spring 管理的Bean | |||
3. 其余可访问的路径,参见文档 | |||
### 3.参考 | |||
## 3.参考 | |||
- actuator文档:https://docs.spring.io/spring-boot/docs/3.0.0-M4/reference/htmlsingle/#actuator | |||
- 具体可以访问哪些路径,参考: https://docs.spring.io/spring-boot/docs/3.0.0-M4/reference/htmlsingle/#actuator.endpoints | |||
- [Spring Boot 官方文档之actuator文档](https://docs.spring.io/spring-boot/docs/3.0.0-M4/reference/htmlsingle/#actuator) | |||
- [Acutator 暴露端点列表](https://docs.spring.io/spring-boot/docs/3.0.0-M4/reference/htmlsingle/#actuator.endpoints) |
@@ -1,10 +1,10 @@ | |||
## spring-boot-demo-admin | |||
# spring-boot-demo-admin | |||
> 本 demo 主要演示了 Spring Boot 如何集成 Admin 管控台,监控管理 Spring Boot 应用,分别为 admin 服务端和 admin 客户端,两个模块。 | |||
### 1.开发步骤 | |||
## 1.开发步骤 | |||
#### 1.1.pom.xml | |||
### 1.1.pom.xml | |||
```xml | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
@@ -48,21 +48,21 @@ | |||
</project> | |||
``` | |||
#### 1.2.admin-server开发 | |||
### 1.2.admin-server开发 | |||
参考 [admin-server 模块](admin-server/README.md) | |||
#### 1.3.admin-client开发 | |||
### 1.3.admin-client开发 | |||
参考 [admin-client 模块](admin-client/README.md) | |||
### 2.测试 | |||
## 2.测试 | |||
1. 进入 [admin-server](admin-server) 服务端,启动管控台服务端程序 | |||
2. 进入 [admin-client](admin-client) 客户端,启动客户端程序,注册到服务端 | |||
3. 打开 `http://localhost:8000` 观察 client 是否注册成功,以及实例注册上来的详细信息 | |||
4. Spring Boot Admin 支持在线查看日志,但是需要客户端事先配置日志,配置好之后,就可以在线查看日志了 | |||
### 3.参考 | |||
## 3.参考 | |||
官方文档:https://codecentric.github.io/spring-boot-admin/3.0.0-M4/#getting-started | |||
- [Spring Boot Admin 官方文档](https://codecentric.github.io/spring-boot-admin/3.0.0-M4/#getting-started) |
@@ -1,10 +1,10 @@ | |||
## spring-boot-demo-admin-client | |||
# spring-boot-demo-admin-client | |||
> 本 demo 主要演示了普通项目如何集成 Spring Boot Admin,并把自己的运行状态交给 Spring Boot Admin 进行展现。 | |||
### 1.开发步骤 | |||
## 1.开发步骤 | |||
#### 1.1.添加依赖 | |||
### 1.1.添加依赖 | |||
```xml | |||
<dependencies> | |||
@@ -38,7 +38,7 @@ | |||
</dependencies> | |||
``` | |||
#### 1.2.增加测试路由以及日志支持 | |||
### 1.2.增加测试路由以及日志支持 | |||
```java | |||
@Slf4j | |||
@@ -58,7 +58,7 @@ public class TestController { | |||
} | |||
``` | |||
#### 1.3.修改配置文件 | |||
### 1.3.修改配置文件 | |||
```yaml | |||
server: | |||
@@ -108,7 +108,7 @@ logging: | |||
file: "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID}){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx" | |||
``` | |||
### 2.测试 | |||
## 2.测试 | |||
1. 启动 `AdminServerApplication` 之后,再启动 `AdminClientApplication`,然后输入 `http://localhost:8080/demo` ,观察 client 程序是否启动成功 | |||
2. 输入 `http://localhost:8080/demo/test` ,观察 admin-server 是否可以在线查看日志 |
@@ -1,10 +1,10 @@ | |||
## spring-boot-demo-admin-server | |||
# spring-boot-demo-admin-server | |||
> 本 demo 主要演示了如何搭建一个 Spring Boot Admin 的服务端项目,可视化展示自己客户端项目的运行状态。 | |||
### 1.开发步骤 | |||
## 1.开发步骤 | |||
#### 1.1.添加依赖 | |||
### 1.1.添加依赖 | |||
```xml | |||
<dependencies> | |||
@@ -26,7 +26,7 @@ | |||
</dependencies> | |||
``` | |||
#### 1.2.启动类配置 | |||
### 1.2.启动类配置 | |||
```java | |||
@EnableAdminServer | |||
@@ -39,7 +39,7 @@ public class AdminServerApplication { | |||
} | |||
``` | |||
#### 1.3.修改配置文件 | |||
### 1.3.修改配置文件 | |||
```yaml | |||
server: | |||
@@ -61,7 +61,7 @@ spring: | |||
``` | |||
### 2.测试 | |||
## 2.测试 | |||
1. 启动 `AdminServerApplication`,然后打开 `http://localhost:8000` | |||
2. 再启动 `AdminClientApplication`,等待启动成功之后,观察是否成功注册上服务端 |
@@ -1,9 +1,10 @@ | |||
## spring-boot-demo-https | |||
# spring-boot-demo-https | |||
> 此 demo 主要演示了 Spring Boot 如何集成 https | |||
### 1.开发步骤 | |||
#### 1.1.添加依赖 | |||
## 1.开发步骤 | |||
### 1.1.添加依赖 | |||
```xml | |||
<dependencies> | |||
@@ -20,7 +21,7 @@ | |||
</dependencies> | |||
``` | |||
#### 1.2.生成证书 | |||
### 1.2.生成证书 | |||
首先使用 jdk 自带的 keytool 命令生成证书复制到项目的 `resources` 目录下 | |||
@@ -46,7 +47,7 @@ CN=xkcoding, OU=spring-boot-demo, O=spring-boot-demo, L=Hangzhou, ST=Zhejiang, C | |||
CN=xkcoding, OU=spring-boot-demo, O=spring-boot-demo, L=Hangzhou, ST=Zhejiang, C=CN | |||
``` | |||
#### 1.3.添加配置 | |||
### 1.3.添加配置 | |||
1. 在配置文件配置生成的证书 | |||
@@ -104,7 +105,7 @@ public class HttpsConfig { | |||
} | |||
``` | |||
### 2.测试 | |||
## 2.测试 | |||
启动 `HttpsApplication`,浏览器访问 `http://localhost:8080/demo/` 将自动跳转到 `https://localhost:8443/demo/` ,同时浏览器地址栏前面还会加一把小锁的标志,代表https已经生效。 | |||
@@ -112,7 +113,7 @@ public class HttpsConfig { | |||
> 1. 自己生成的证书浏览器会有危险提示,去ssl网站上使用金钱申请则不会 | |||
> 2. Chrome 浏览器会因为证书不可信导致无法访问,因此测试请使用 FireFox 浏览器 | |||
### 3.参考 | |||
## 3.参考 | |||
- `keytool`命令参考 | |||
@@ -1,14 +1,14 @@ | |||
## spring-boot-demo-docker | |||
# spring-boot-demo-docker | |||
> 本 demo 主要演示了如何容器化一个 Spring Boot 项目。通过 `Dockerfile` 的方式打包成一个 images 。 | |||
### 1.开发步骤 | |||
## 1.开发步骤 | |||
#### 1.1.创建一个 HelloWorld 的 SpringBoot 项目 | |||
### 1.1.创建一个 HelloWorld 的 SpringBoot 项目 | |||
参考 `demo-base-helloworld` 案例即可 | |||
#### 1.2.创建Dockerfile | |||
### 1.2.创建Dockerfile | |||
```dockerfile | |||
# 多阶段构建 | |||
@@ -39,7 +39,7 @@ EXPOSE 8080 | |||
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/urandom","org.springframework.boot.loader.JarLauncher"] | |||
``` | |||
#### 1.2.打包 | |||
### 1.2.打包 | |||
1. 首先在 spring-boot-demo 根目录下,先执行编译打包 Jar 文件 | |||
@@ -73,7 +73,7 @@ $ docker run -p 8080:8080 demo-package-docker:v1 | |||
> 1.Spring Boot 提供的 maven 插件中已包含 `spring-boot-loader-tools` 依赖,该依赖可以将 SpringBoot FatJar 解压为每个layer,这样在 Docker 多阶段构建的时候,可以让 Docker 复用已存在的 layer,达到加速构建、加速上传、加速下载的目的 | |||
> 2.同学们可以通过修改代码、添加依赖等方式重新 build 不同版本的镜像,然后通过 `docker inspect xxx` 命令对比不同版本的 layer,观察输出信息是否存在相同的 layer sha256 值,存在即表示 Docker 已经复用了该 layer | |||
### 2.参考 | |||
## 2.参考 | |||
- [Spring Boot 官方文档之镜像构建](https://docs.spring.io/spring-boot/docs/3.0.0-M4/reference/htmlsingle/#container-images.dockerfiles) | |||
- [Docker 官方文档](https://docs.docker.com/) | |||
@@ -1,9 +1,10 @@ | |||
## spring-boot-demo-war | |||
# spring-boot-demo-war | |||
> 本 demo 主要演示了如何将 Spring Boot 项目打包成传统的 war 包程序。 | |||
### 1.开发步骤 | |||
#### 1.1.修改启动类 | |||
## 1.开发步骤 | |||
### 1.1.修改启动类 | |||
```java | |||
@SpringBootApplication | |||
@@ -23,7 +24,7 @@ public class WarApplication extends SpringBootServletInitializer { | |||
} | |||
``` | |||
#### 1.2.修改 pom.xml | |||
### 1.2.修改 pom.xml | |||
```xml | |||
<!-- 若需要打成 war 包,则需要将打包方式改成 war --> | |||
@@ -58,6 +59,6 @@ public class WarApplication extends SpringBootServletInitializer { | |||
</build> | |||
``` | |||
### 2.参考 | |||
## 2.参考 | |||
- [Spring Boot 官方文档之传统部署方式](https://docs.spring.io/spring-boot/docs/3.0.0-M4/reference/htmlsingle/#howto.traditional-deployment.war) |