数据安全考虑数据库账号密码做个加密处理
添加依赖库
com.github.ulisesbocchio
jasypt-spring-boot-starter
3.0.0
添加key
jasypt.encryptor.password=EbfYkitulv73I2p0mXI50JMXoaxZT55
值可以随便改。
生成加密字符串
package com.example.modeltree.controller;
import com.example.modeltree.ModeltreeApplication;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "密码")
@RestController
@RequestMapping("/demo")
public class DemoController {
@Autowired
StringEncryptor encryptor;
@GetMapping("/get")
@ApiOperation(value = "get", notes = "get")
@ResponseBody
public void test() {
String username = encryptor.encrypt("root");
System.out.println(username);
String password = encryptor.encrypt("123");
System.out.println(password);
}
}
请求接口打印生成密钥,修改配置文件即可
#用户名 spring.datasource.username=ENC(X3C/6C4lu6iv34NN5jsMWWGKyUE8+ZnoobDAA8575JKGnvPWa5NYcAiSq1/pZSzo) #密码 spring.datasource.password=ENC(445VNaUSM8IEuT+FzCWJR23ToXXcj5Wlni/jPX5EEZ9PZ+zZ3O74240nE+q5/WYr)
问题:
手动测试可以关闭手动测试可以关闭
可以加上
org.apache.maven.plugins maven-surefire-plugintrue
参考文档
springboot中数据库配置加密_heiyouling_51CTO博客
Maven 编译:Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date]_Crazy的博客-CSDN博客



