springboot的config文件通常如下:
spring.data.jdbc.url=jdbc:mysql://127.0.0.1:3305/test_db
spring.data.jdbc.username=root
spring.data.jdbc.password=123456
通常会将敏感信息加密,一般的解决方案会在config的bean中进行逻辑解密代码的处理,但是不够优美,这里介绍一种更好的思路和方案,拿现有的一个实现jasypt。
项目地址:https://github.com/ulisesbocchio/jasypt-spring-boot
使用步骤:
1、springboot项目引入依赖,使用@AutoConfiguration
<!-- https://mvnrepository.com/artifact/com.github.ulisesbocchio/jasypt-spring-boot-starter -->
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>
2、生成密文
java -c