- 首先你使用的的是Java的springboot项目
- 你的项目的pom.xml加入了druid依赖,如下
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
- 生成密文
打开maven依赖的repository,执行一下命令:生成xxx的密文
java -cp druid-1.1.10.jar com.alibaba.druid.filter.config.ConfigTools xiucai315
privateKey:MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAlgiTZIxr/Ch23ZHFToN2DHMGqsCOnT4PMQgXDdDW1H2VFJ+54wwnZOA6cZTLtzZlEmX0ihdgqL1Nu5oP2s81MwIDAQABAkBdZzlbf5A6i3Z0uit7lZwIZBPieb5PZjNO8xpnH3yfDBuU/lmCgtdjGpqyrNjg15dIozQCqM/ibYvP+A5ICCABAiEAx3TSjDngd3cmVcd0BiwwYtxc8YsPEF/mWRDhaMXpwYECIQDAkPtEi3o7b7izymgtqgqtE7xVR+/nAMYzhyiAIQDoswIgZ4yW4oYJqvwIwu/RpIK8fBa7igsPvwiKpiLFY4ecXAECIAWn/Ilt42A9jtpRFrBIr1mYG88Rdt19K1U2Ih1pWsJ7AiEAxsAvPyLdHHFaRiAk0Xh+jx+aUi+0OLdrjruTiB9Tr4c=
publicKey:MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJYIk2SMa/wodt2RxU6DdgxzBqrAjp0+DzEIFw3Q1tR9lRSfueMMJ2TgOnGUy7c2ZRJl9IoXYKi9TbuaD9rPNTMCAwEAAQ==
password:k0ciEXIN4XCj0dviYh2eTtsOf+nWbJG7HJR4VBhiLOPh4ObHOwEhoOB/c5dzKQ1H3UqnQnczj5j7Sg9wjOK3xQ==
- 打开application.properties增加如下配置
spring.datasource.password= 上面的password
# 公钥
publickey=上面的publicKey
# 配置 connection-properties,启用加密,配置公钥。
spring.datasource.druid.connection-properties=config.decrypt=true;config.decrypt.key=${publickey}
# 启动ConfigFilter
spring.datasource.druid.filter.config.enabled=true
- 运行你的应用,看数据库连接成功!
完毕!