jasypt-spring-boot-starter 配置属性介绍
时间: 2024-09-24 18:21:13 浏览: 224
Jasypt-Spring-Boot-Starter 是一个用于简化 Spring Boot 应用程序中对敏感信息加密的工具。在配置上,开发者通常会做以下步骤:
1. 添加依赖[^1]:
```xml
<dependency>
<groupId>org.jasypt.spring.boot</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>
```
2. 在`application.properties` 或 `application.yml` 中设置加密相关的属性。例如,你可以定义一个明文密码:
```properties
spring.jasypt.encryptor.password=your_secret_key
```
其他可能的属性还包括:
- `spring.jasypt.encryptor.algorithm`: 加密算法,默认为`PBEWithMD5AndTripleDES`。
- `spring.jasypt.encryptor.passwordEncoder`: 自定义密码编码器。
3. 使用`@Value`注解从环境变量加载加密后的值:
```java
@Value("${your.property.name}")
private String encryptedValue;
// 解密后使用
String decryptedValue = EncryptorService.decrypt(encryptedValue);
```
4. 如果需要加密特定的bean属性,可以使用`@ConfigurationProperties` 和 `@Encryptable` 注解:
```java
@ConfigurationProperties(prefix = "my.config")
public class AppConfig {
@Encryptable
private String sensitiveField;
}
```
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![jar](https://img-home.csdnimg.cn/images/20210720083455.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)