admin管理员组文章数量:1589766
为了避免在配置文件直接明文写敏感信息, 使用加密可以解决尴尬
- pom文件添加依赖
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
- 配置文件中声明加密方式
#jasypt加密的密匙
jasypt:
encryptor:
password: EbfYkitulv73I2p0mXI50JMXoaxZTKJ7
- 获取加密后的信息
@RunWith(SpringRunner.class)
@SpringBootTest
@WebAppConfiguration
public class PasswordTest {
@Autowired
StringEncryptor encryptor;
@Test
public void getPass() {
String pass = "ccccccc";
System.out.println("加密密码: "+encryptor.encrypt(pass));
}
}
- 完善配置文件,其中 ENC()为固定格式,括号内为加密后的配置信息
#jasypt加密的密匙
jasypt:
encryptor:
password: EbfYkitulv73I2p0mXI50JMXoaxZTKJ7
spring:
application:
name: config-server
cloud:
config:
server:
git:
username: ENC(ZPLrNxi7LgvCThEDxWhSKTtMqh1bitSUMqcHhYFjo5M=)
uri: ENC(D+BA0BfsYDvQFaWPg2BcEzAjgieC5ljeTcOIBRqtBCj+bFvt2BmjW5tybSUzVkdvn5pqZAjIX5U=)
password: ENC(d8cI/u82lOmpaazl9+FfkpuYIcIct1Bj)
search-paths:
server:
port: 7001
版权声明:本文标题:spring boot 中配置文件加密 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1728075070a1144381.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论