步骤一:先生成加密的密码:
步骤二:配置application.yaml文件:
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
druid:
username: root
password: aPJ35s+aFz6ASmnmNtW2F8ttxru9mNCuX0upxY8N4dpT/vY//4rDRpClt784GtP5wXm2tRUQgbMNudQryvCR+A==
url: jdbc:mysql://xx.xx.xxx.xxx:3306/cityinfo?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
initial-size: 5
min-idle: 5
max-active: 20
max-wait: 60000
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
validation-query: SELECT 1 FROM DUAL
test-while-idle: true
test-on-borrow: false
test-on-return: false
pool-prepared-statements: false
#配置监控统计拦截的filters,stat:监控统计、log4j:⽇志记录、wall:防御sql注入
#如果允许时报错 java.lang.ClassNotFoundException: org.apache.log4j.Priority
#则导入 log4j 依赖即可,Maven 地址:https://mvnrepository.com/artifact/log4j/log4j
filters: stat,wall,log4j,config
#指定每个连接上PSCache的大小
max-pool-prepared-statement-per-connection-size: 20
#合并多个DruidDataSource的监控数据,多数据源做主从时使用
use-global-data-source-stat: true
#通过connectProperties属性来打开mergeSql功能;慢SQL记录
connect-properties:
druid.stat.logSlowSql: true
druid.stat.slowSqlMillis: 5000
config.decrypt: true
config.decrypt.key: MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJAg7cxPhDRczpTuqjnHgZlfztB4gwCxso+Ysz+Ohw4tshdDLmP9ziTj3DEyWkBbsR3Dte4X10xa6oh1nvZkyj0CAwEAAQ==
# config.decrypt.key: ${your_public_key}