依赖引用

在您的Spring Boot项目的pom.xml中添加以下依赖

Spring Boot 2(java8)

      <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)

      <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对象存储

可参考官方文档开通cos,然后在访问管理控制台找到下面accessKeysecretKey,在控制台找到regionbucket,在自定义源站域名将自己的域名与源站关联,用于访问和管理网站或应用的内容。您可将已备案的自定义域名绑定到存储桶,通过自定义源站域名访问存储桶内的对象

      # 腾讯云cos对象存储
liyao:
  cos:
  	enabled: true
    accessKey: # 身份识别ID,可在腾讯云API密钥管理页面获取  
    secretKey: # 身份密钥, 可在腾讯云API密钥管理页面获取
    region: # 地域信息
    bucket: # 存储桶名称
    domain: # 自定义源站域名,格式为https://example.com
    

验证码

可选类型如下

  • ARITHMETIC 算术类型
  • CHINESE 中文类型
  • CHINESE_GIF 中文gif类型
  • GIF gif类型
  • SPEC png类型
      # 验证码
liyao:
  captcha:
   # 验证码类型
    type: SPEC
   #过期时间
    ttl: 180
    

Redis配置

本starter已经预配置了RedisTemplate,使用JSON序列化,可以直接注入使用

      @Resource
private RedisTemplate<String, Object> redisTemplate;

// 使用示例
redisTemplate.opsForValue().set("key", value);
    

限流器

      liyao:
 system:
  rate-limiter-count: 10  # 同一IP每秒最多请求次数
    

代码生成

需提前在resource/templates下准备freemaker模板文件,将下面信息填好后可快速生成crud

       # 代码生成
liyao:
  generator:
    #是否开启代码生成器
    enabled: false
    # 生成的包名
    package-name: com.starter.springbootInit
     # 为模板文件提供的实体类
    input-file: com.starter.springbootInit.model.entity.Excel
    data-name: excel
    

license授权

使用 keytool 生成公私钥证书库

例如:私钥库密码为 private123456,公钥库密码为 public123456,生成步骤如下:

      # 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官方文档

完整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               # 退出登录
    

声明

作者: liyao

版权:本博客所有文章除特别声明外,均采用CCBY-NC-SA4.O许可协议。转载请注明!

最后更新于 2025-09-30 20:31 history