Home > Java > javaTutorial > body text

How to configure Springboot2 integrated druid encrypted database password

WBOY
Release: 2023-05-11 11:31:05
forward
1128 people have browsed it

One: Environment

springboot 2.x
druid 1.1.21

Two: druid encrypted database password

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

java -cp jar包路径 com.alibaba.druid.filter.config.ConfigTools 数据库密码
java -cp druid-1.1.21.jar com.alibaba.druid.filter.config.ConfigTools 数据库密码
Copy after login

Successful operation output

privateKey:MIIBVAIBAD...
publicKey:MFwwDQYJKo...
password:PNd/zcG JEn. ..

Fill the obtained publicKey and password into the yml configuration file respectively

3: Single data source

Add dependencies

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.1.21</version>
</dependency>
Copy after login

yml configuration

spring:
  datasource:
    name: 名称
    url: 地址
    username: 用户名
    password: 加密后的密码
    driver-class-name: com.mysql.cj.jdbc.Driver
    # druid
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      #特别提示:配置数据库加密 config这个不能忘掉
      filters: stat,wall,config
      use-global-data-source-stat: true
      # 开启解密config.decrypt=true; 公钥:config.decrypt.key
      connect-properties:
        druid.stat.mergeSql: true
        druid.stat.slowSqlMillis: 5000
        druid.stat.logSlowSql: true
        config.decrypt: true
        config.decrypt.key: 公钥
      # 连接池的配置信息
      # 初始化大小,最小空闲连接数,最大活跃数
      initial-size: 5
      min-idle: 5
      maxActive: 20
      # 配置获取连接等待超时的时间
      maxWait: 60000
      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
      timeBetweenEvictionRunsMillis: 60000
      # 配置一个连接在池中最小生存的时间,单位是毫秒
      minEvictableIdleTimeMillis: 300000
      validationQuery: SELECT 1 FROM DUAL
      testWhileIdle: true
      testOnBorrow: false
      testOnReturn: false
      # 打开PSCache,并且指定每个连接上PSCache的大小
      poolPreparedStatements: true
      maxPoolPreparedStatementPerConnectionSize: 20
Copy after login

Four: Multiple data sources

Add dependencies

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.1.21</version>
</dependency>

   com.baomidou
   dynamic-datasource-spring-boot-starter
   2.5.3
Copy after login

Startup class configuration

@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)
Copy after login

eg:

How to configure Springboot2 integrated druid encrypted database password

ymlconfig

spring:
  datasource:
    dynamic:
      # 默认数据源
      primary: CLOUD
      datasource:
        CLOUD:
          url: 数据库地址
          username: 用户名
          password: 加密后的密码
          driver-class-name: com.mysql.cj.jdbc.Driver
          druid:
            public-key: 加密后的公钥
        WAREHOUSE:
          driver-class-name: com.mysql.cj.jdbc.Driver
          url: 数据库地址
          username: 用户名
          password: 加密后的密码
          druid:
            public-key: 加密后的公钥
Copy after login

The above is the detailed content of How to configure Springboot2 integrated druid encrypted database password. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!