需求:手写一个加密的spring-boot-start,按着用户定义的加密算法(可选:MD5、SHA)去加密内容
新建一个maven项目

新建好的项目结构和pom.xml如图
 
添加pom.xml
完整的pom.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.11</version>
        <relativePath/>
    </parent>
    <groupId>com.cao</groupId>
    <artifactId>mydigest-springboot-starter</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
    <dependencies>
        <!--包含自动配置的代码-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
        </dependency>
        <!--非必须:编写配置文件时会有提示-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <!--该starter要用到的加密依赖-->
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.15</version>
        </dependency>
    </dependencies>
</project>
新加的文件内容标记
 
新加业务内容
项目的内容在https://gitee.com/cao_wen_bin/my_springboot_starter_digest
 如图结构
 
 代码编写完成之后
 进行打包,并将打包后的包安装到本地maven仓库
 
 查看是否安装成功。
 
测试
在随便另外的一个项目中,引入自己刚刚写的这个依赖
<dependency>
    <groupId>com.cao</groupId>
    <artifactId>mydigest-springboot-starter</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

测试SHA算法加密
在application.yml文件中进行配置
digest:
  type: sha

 测试类查看结果:
 
测试MD5算法加密
在application.yml文件中进行配置
digest:
  type: md5

 测试类查看结果:
 
 以上测试证明自己手写的mydigest-springboot-starter是没有问题的



















