考虑到安全性,最好将配置文件中的敏感信息进行加密。例如说,MySQL 的用户名密码、第三方平台的Token令牌等等
Nacos + Jasypt 配置加密
- 1、增加pom引入
<!-- 实现对 Jasypt 实现自动化配置 --> <dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>3.0.2</version> </dependency>
- 2、新增nacos配置
- 3、JasyptTest 测试类进行加密
package com.example.nacosConfig.controller; import org.jasypt.encryption.StringEncryptor; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.S