<p><img alt="" height="167" src="https://i-blog.csdnimg.cn/blog_migrate/2f2efd86d6abd7919ae81188.png" width="818" /></p>
讯享网
讯享网<!-- 阿里数据库连接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-3-starter</artifactId> <version>1.2.21</version> </dependency>
# Spring配置 spring: # 数据源配置 datasource: type: com.alibaba.druid.pool.DruidDataSource #开启多数据源取消这个配置在master和slave下配置 #driverClassName: com.mysql.cj.jdbc.Driver druid: # 主库数据源 master: url: jdbc:mysql://192.168.1.23:3306/demo?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root password: V2MQgERfNwkoYXkiMcYLCsy45HAEc9EVrhR5VNAPTwFx4ycayVWvlqxkYYCQuujccoVFJ5MZVROkVyjUgsl2NQ== #DruidEncryptorUtils类生成密码和公钥,之后开启druid:filter:config:enabled=true publicKey: MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMCh+KGwVH6CERudOz1Fyr+kgUSvjxwcbuv9b8rKAv++lwTA9iLqXc+eUW37PUWns+4+uJ6Y2WRsO084RmXhsi0CAwEAAQ== connectionProperties: config.decrypt=true;config.decrypt.key=${spring.datasource.druid.master.publicKey} slave: enabled: false url: jdbc:sqlserver://192.168.1.224:1433;SelectMethod=cursor;DatabaseName=genocs username: sa password: 123 # 初始连接数 initialSize: 5 # 最小连接池数量 minIdle: 10 # 最大连接池数量 maxActive: 20 # 配置获取连接等待超时的时间 maxWait: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 timeBetweenEvictionRunsMillis: 60000 # 配置一个连接在池中最小生存的时间,单位是毫秒 minEvictableIdleTimeMillis: # 配置一个连接在池中最大生存的时间,单位是毫秒 maxEvictableIdleTimeMillis: # 配置检测连接是否有效 validationQuery: SELECT 1 FROM DUAL testWhileIdle: true testOnBorrow: false testOnReturn: false webStatFilter: enabled: true statViewServlet: enabled: true # 设置白名单,不填则允许所有访问 allow: url-pattern: /druid/* # 控制台管理用户名和密码 login-username: admin login-password: pw2024 filter: stat: enabled: true # 慢SQL记录 log-slow-sql: true slow-sql-millis: 1000 merge-sql: true wall: config: multi-statement-allow: true config: enabled: true
- 生成的公钥和密码配置在这里,用下面的工具类生成
#DruidEncryptorUtils类生成密码和公钥,之后开启druid:filter:config:enabled=true publicKey: MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMCh+KGwVH6CERudOz1Fyr+kgUSvjxwcbuv9b8rKAv++lwTA9iLqXc+eUW37PUWns+4+uJ6Y2WRsO084RmXhsi0CAwEAAQ==
connectionProperties: config.decrypt=true;config.decrypt.key=${spring.datasource.druid.master.publicKey}
- 这个配置是必须开启的
config:
enabled: true

- 生成方法
讯享网import com.alibaba.druid.filter.config.ConfigTools;public class DruidEncryptorUtils { public static void main(String[] args) {try { String password = "G@2023"; String[] arr = ConfigTools.genKeyPair(512); //System.out.println("privateKey:" + arr[0]); System.out.println("publicKey:" + arr[1]); System.out.println("password:" + ConfigTools.encrypt(arr[0], password)); } catch (Exception e) { e.printStackTrace(); }} }
- 生成的公钥和密码

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/174980.html