---
date: 2025-03-28 02:40:47
title: 快速开始
permalink: /pages/571de5
tags:
  - Spring Boot
author:
  name: 华总
  link: https://xiaoying.org.cn
categories:
  - 后端
  - 功能扩展
  - 通用模块

---


## 依赖引用

::: tip 

依赖可能非最新版本，请前往maven获取最新版本

[Spring Boot 2](https://central.sonatype.com/artifact/io.github.liyao52033/common-spring-boot-starter)地址

[Spring Boot 3](https://central.sonatype.com/artifact/io.github.liyao52033/liyao-spring-boot3-starter-common)地址

:::

在您的Spring Boot项目的`pom.xml`中添加以下依赖

Spring Boot 2(java8)

```xml
<dependency>
  <groupId>io.github.liyao52033</groupId>
  <artifactId>common-spring-boot-starter</artifactId>
  <version>1.2.4</version>
</dependency>

<dependency>
    <groupId>io.github.liyao52033</groupId>
    <artifactId>ErrorCode-spring-boot-starter</artifactId>
    <version>1.2.0</version>
</dependency>

<dependency>
  <groupId>com.hccake</groupId>
  <artifactId>ballcat-spring-boot-starter-easyexcel</artifactId>
  <version>1.4.1</version>
</dependency>
```

Spring Boot 3(java17)

```xml
<dependency>
    <groupId>io.github.liyao52033</groupId>
    <artifactId>liyao-spring-boot3-starter-common</artifactId>
    <version>1.2.0</version>
</dependency>

<dependency>
    <groupId>io.github.liyao52033</groupId>
    <artifactId>liyao-spring-boot3-starter-ErrorCode</artifactId>
    <version>1.2.0</version>
</dependency>

<dependency>
    <groupId>io.github.liyao52033</groupId>
    <artifactId>liyao-spring-boot-starter-fastexcel</artifactId>
    <version>1.2.0</version>
</dependency>
```



## yml配置

### cos对象存储

可参考[官方文档](https://cloud.tencent.com/document/product/436/38484?from=console_document_search)开通cos，然后在[访问管理控制台](https://console.cloud.tencent.com/cam/capi)找到下面`accessKey`与`secretKey`，在[控制台](https://console.cloud.tencent.com/cos/bucket?bucket=aurora-1258839075&region=ap-shanghai&type=bucketoverview)找到`region`与`bucket`，在[自定义源站域名](https://console.cloud.tencent.com/cos/bucket?bucket=aurora-1258839075&region=ap-shanghai&type=domainconfig&anchorType=customizeDomain)将自己的域名与源站关联，用于访问和管理网站或应用的内容。您可将已备案的自定义域名绑定到存储桶，通过自定义源站域名访问存储桶内的对象

::: warning

enabled是**Spring Boot 3**版本特有，**Spring Boot 2**版本只要引入此依赖就会自动装配，需提前在yml配置好相关参数，不然启动会报错

:::

```yml
# 腾讯云cos对象存储
liyao:
  cos:
  	enabled: true
    accessKey: # 身份识别ID,可在腾讯云API密钥管理页面获取  
    secretKey: # 身份密钥, 可在腾讯云API密钥管理页面获取
    region: # 地域信息
    bucket: # 存储桶名称
    domain: # 自定义源站域名，格式为https://example.com
```



### 验证码

::: warning

Spring Boot 3不支持`ARITHMETIC`  算术类型

:::

可选类型如下

- `ARITHMETIC`  算术类型 
- `CHINESE`  中文类型
- `CHINESE_GIF`  中文gif类型
- `GIF`    gif类型
- `SPEC`  png类型

```yml
# 验证码
liyao:
  captcha:
   # 验证码类型
    type: SPEC
   #过期时间
    ttl: 180
```



###   Redis配置

本starter已经预配置了RedisTemplate，使用JSON序列化，可以直接注入使用

```java
@Resource
private RedisTemplate<String, Object> redisTemplate;

// 使用示例
redisTemplate.opsForValue().set("key", value);
```



### 限流器

```yaml
liyao:
 system:
  rate-limiter-count: 10  # 同一IP每秒最多请求次数
```



### 代码生成

需提前在`resource/templates`下准备`freemaker`[模板文件](https://pan.xiaoying.org.cn/s/AOf3)，将下面信息填好后可快速生成crud

```yml
 # 代码生成
liyao:
  generator:
    #是否开启代码生成器
    enabled: false
    # 生成的包名
    package-name: com.starter.springbootInit
     # 为模板文件提供的实体类
    input-file: com.starter.springbootInit.model.entity.Excel
    data-name: excel
```



### license授权

使用 keytool 生成公私钥证书库

例如：私钥库密码为 private123456，公钥库密码为 public123456，生成步骤如下：

```bash
# 1. 生成私钥库
# validity：私钥的有效期（天）
# alias：私钥别称
# keystore：私钥库文件名称（生成在当前目录）
# storepass：私钥库密码（获取 keystore 信息所需的密码，密钥库口令）
# keypass：别名条目的密码(密钥口令)
keytool -genkeypair -keysize 1024 -validity 3650 -alias "privateKey" -keystore "privateKeys.keystore" -storepass "public123456" -keypass "private123456" -dname "CN=localhost, OU=localhost, O=localhost, L=SH, ST=SH, C=CN"

# 2. 把私钥库内的公钥导出到一个文件当中
# alias：私钥别称
# keystore：私钥库的名称（在当前目录查找）
# storepass：私钥库的密码
# file：证书名称
keytool -exportcert -alias "privateKey" -keystore "privateKeys.keystore" -storepass "pubwd123456" -file "certfile.cer"

# 3.再把这个证书文件导入到公钥库，certfile.cer 没用了可以删掉了
# alias：公钥名称
# file：证书名称
# keystore：公钥文件名称
# storepass：公钥库密码
keytool -import -alias "publicCert" -file "certfile.cer" -keystore "publicCerts.keystore" -storepass "public123456"
```

更多配置请查看[TrueLicense官方文档](https://github.com/JCXTB/TrueLicense)

## 完整yml

```yml
liyao:
  # 腾讯云cos对象存储
  cos:
    accessKey: # 身份识别ID,可在腾讯云API密钥管理页面获取  
    secretKey: # 身份密钥, 可在腾讯云API密钥管理页面获取
    region: # 地域信息
    bucket: # 存储桶名称格式
    domain: # 自定义域名
    
  # 验证码
  captcha:
   # 验证码类型
    type: ARITHMETIC
   #过期时间
    ttl: 180
    
  # 代码生成
  generator:
    #是否开启代码生成器
    enabled: false
    # 生成的包名
    package-name: com.starter.springbootInit
     # 模板文件位置
    input-file: com.starter.springbootInit.model.entity.Excel
    data-name: excel
    
  # 是否开启接口日志
  log:
    enabled: true
  
  # 限流器
  system:
    rate-limiter-count: 10  # 限流次数
    
 # license授权
  license:
   # 是否开启接口授权
    enabled: true
    # 主题
    subject: starter
    # 公钥别称
    publicAlias: 
    # 访问公钥的密码
    publicKeystorePass: 
    # license授权文件位置
    licensePath: 
    # 公钥所在的位置
    publicKeysStorePath: 
    # 将license授权文件上传的位置
    uploadPath: 
    # 排除授权验证的接口
    allowed-paths:
      - /api/license/getServerInfos    #获取服务器硬件信息
      - /api/license/generateLicense   #生成授权文件
      - /api/license/uploadLicense     #上传授权文件
      - /api/captcha/get               #生成验证码
      - /api/captcha/check             #验证验证码
      - /api/user/login                #登录
      - /api/user/register             #注册
      - /api/user/getInfo              # 获取当前登录用户
      - /api/user/logout               # 退出登录



```

