Get the App
SLTechnology News&Howtos  ›  Development  › 

How to configure the password of Springboot2 Integrated druid encryption Database

Shulou Source: shulou.com Published: 2022-06-01 01:00:54 10月02日 Update

This article mainly introduces the Springboot2 integrated druid encryption database password configuration related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this Springboot2 integrated druid encryption database password configuration article will have a harvest, let's take a look.

One: environment

Springboot 2.x

Druid 1.1.21

Two: druid encrypts the database password

Download the druid-1.1.21.jar package locally, run cmd, and enter the command

Java-cp jar package path com.alibaba.druid.filter.config.ConfigTools database password java-cp druid-1.1.21.jar com.alibaba.druid.filter.config.ConfigTools database password

Run successfully output

PrivateKey:MIIBVAIBAD...

PublicKey:MFwwDQYJKo...

Password:PNd/zcG+JEn...

Fill the resulting publicKey and password into the yml configuration file respectively.

Three: single data source

Add dependency

Com.alibaba druid-spring-boot-starter 1.1.21

Yml configuration

Spring: datasource: name: name url: address username: user name password: encrypted password driver-class-name: com.mysql.cj.jdbc.Driver # druid type: com.alibaba.druid.pool.DruidDataSource druid: # Special Tip: configure database encryption config this can not forget filters: stat,wall Config use-global-data-source-stat: true # enable decryption config.decrypt=true Public key: config.decrypt.key connect-properties: druid.stat.mergeSql: true druid.stat.slowSqlMillis: 5000 druid.stat.logSlowSql: true config.decrypt: true config.decrypt.key: public key # configuration information of connection pool # initialization size, minimum number of idle connections Maximum number of active initial-size: 5 min-idle: 5 maxActive: 20 # configure the time to get connection wait timeout maxWait: 60000 # configure how often to detect idle connections that need to be closed, in milliseconds timeBetweenEvictionRunsMillis: 60000 # configure the minimum survival time of a connection in the pool Unit: millisecond minEvictableIdleTimeMillis: 300000 validationQuery: SELECT 1 FROM DUAL testWhileIdle: true testOnBorrow: false testOnReturn: false # Open PSCache and specify the size of the PSCache on each connection poolPreparedStatements: true maxPoolPreparedStatementPerConnectionSize: 20 IV: multiple data sources

Add dependency

Com.alibaba druid-spring-boot-starter 1.1.21 com.baomidou dynamic-datasource-spring-boot-starter 2.5.3

Startup class configuration

@ SpringBootApplication (exclude = DruidDataSourceAutoConfigure.class)

Eg:

Yml configuration

Spring: datasource: dynamic: # default data source primary: CLOUD datasource: CLOUD: url: database address username: user name password: encrypted password driver-class-name: com.mysql.cj.jdbc.Driver druid: public-key: encrypted public key WAREHOUSE: driver-class-name: com.mysql.cj.jdbc.Driver url: database address username: user name password: encrypted password druid: public-key: encrypted public key on "how to configure Springboot2 integrated druid encrypted database password" this article ends here Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "Springboot2 integrated druid encryption database password configuration". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Tags: Data configuration encryption password database public key address data source user user name knowledge minimum content unit size time idle article detection run Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Redmi Xiaomi Microsoft vpn