springboot 的yaml配置文件加密
一、采用yaml 插件加密
使用Jasypt对Spring Boot的YAML配置文件进行加密是一种保护敏感信息(如数据库密码、API密钥等)的有效方法。Jasypt(Java Simplified Encryption)是一个Java加密工具库,它提供了一种简单的方式来实现文本的加密和解密。下面是如何在Spring Boot项目中集成Jasypt并加密YAML配置的步骤:
添加依赖
首先,在你的pom.xml或build.gradle文件中添加Jasypt Spring Boot Starter的依赖。
<!-- jasypt加密依赖-->
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>
implementation 'com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.5' // 请检查最新版本
创建启动类
我们需要在启动类上加上一个@EnableEncryptableProperties开启jasypt配置
@SpringBootApplication
@EnableEncryptableProperties
public class FileServerApplication {
public static