微积壹佰 网站建设,wordpress安装dplayer,做一个手机app的步骤,全网视频合集网站建设背景
Druid连接池是阿里巴巴开源的数据库连接池项目。Druid连接池为监控而生#xff0c;内置强大的监控功能#xff0c;监控特性不影响性能。功能强大#xff0c;能防SQL注入#xff0c;内置Loging能诊断Hack应用行为。现在已经SpringBoot3#xff0c;Druid的配置也需要随…背景
Druid连接池是阿里巴巴开源的数据库连接池项目。Druid连接池为监控而生内置强大的监控功能监控特性不影响性能。功能强大能防SQL注入内置Loging能诊断Hack应用行为。现在已经SpringBoot3Druid的配置也需要随着更新。
SpringBoot3整合Druid
在SpringBoot3中整合Druid连接池可以通过以下步骤进行配置 添加依赖在项目的pom.xml文件中添加Druid的Spring Boot Starter依赖。 druid.version1.2.23/druid.version!-- https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-3-starter --
dependencygroupIdcom.alibaba/groupIdartifactIddruid-spring-boot-3-starter/artifactIdversion${druid.version}/version
/dependency 同时确保已经添加了数据库驱动的依赖例如MySQL !--dependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdversion${mysql.version}/version
/dependency--
dependencygroupIdorg.postgresql/groupIdartifactIdpostgresql/artifactIdversion${postgresql.version}/version
/dependency 配置YAML在application.yml中配置数据源和Druid连接池的参数。 spring:datasource:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/test?characterEncodingutf8serverTimezoneAsia/Shanghaiusername: rootpassword: root123druid:initial-size: 5min-idle: 5max-active: 20max-wait: 60000time-between-eviction-runs-millis: 60000min-evictable-idle-time-millis: 30000validation-query: select xtest-while-idle: truetest-on-borrow: falsetest-on-return: falsepool-prepared-statements: falsefilters: stat,wall,slf4jmax-pool-prepared-statement-per-connection-size: -1use-global-data-source-stat: trueconnect-properties: druid.stat.mergeSqltrue;druid.stat.slowSqlMillis5000web-stat-filter:enabled: trueurl-pattern: /*exclusions: /druid/*,*.js,*.gif,*.jpg,*.png,*.css,*.icostat-view-servlet:enabled: trueurl-pattern: /druid/*reset-enable: falselogin-username: druidlogin-password: druidallow: 127.0.0.1deny: 启动项目启动Spring Boot应用后Druid连接池将自动配置并可以使用。你可以通过访问Druid提供的监控页面来查看数据库连接池的状态。监控页面的访问地址通常是http://localhost:8080/druid/login.html输入配置的用户名和密码即可登录。
以上步骤是基本方法仅供具体配置可能会根据Druid版本和Spring Boot版本的不同有所变化。在实际操作时建议参考Druid的官方文档和Spring Boot的官方文档进行配置。 Druid监控
http://localhost:12666/api/system/druid/login.html
http://localhost:12666/api/system/druid/index.html Github参考代码
当然你也可以参考SpringBoot3脚手架之MySpringBootAPI部分下载即可开始使用DRUID已配置。https://github.com/moshowgame/MySpringBootAPIhttps://github.com/moshowgame/MySpringBootAPI
filterslog4j ClassNotFoundException: org.apache.log4j.Priority issue
可以改为 filters: stat,wall,slf4j 或者干脆不要log4j和slf4j Error starting ApplicationContext. To display the condition evaluation report re-run your application with debug enabled.
2024-09-29T19:24:22.89208:00 ERROR 9648 --- [MySpringBootAPI] [ main] o.s.b.d.LoggingFailureAnalysisReporter : ***************************
APPLICATION FAILED TO START
***************************Description:Failed to bind properties under spring.datasource.druid to com.alibaba.druid.spring.boot3.autoconfigure.DruidDataSourceWrapper:Property: spring.datasource.druid.filtersValue: stat,wall,log4jOrigin: class path resource [application-dev.yml] - 52:18Reason: java.lang.ClassNotFoundException: org.apache.log4j.PriorityAction:Update your applications configurationProcess finished with exit code 1 Application 完整YAML参考
server:port: 12666servlet:context-path: /apiundertow:threads:io: 4worker: 20url-charset: UTF-8
spring:banner:charset: UTF-8application:name: MySpringBootAPIfreemarker:request-context-attribute: requestsuffix: .htmlcontent-type: text/htmlenabled: truecache: falsecharset: UTF-8allow-request-override: falseexpose-request-attributes: trueexpose-session-attributes: trueexpose-spring-macro-helpers: truetemplate-loader-path: classpath:/templates/settings:number_format: 0.##mvc:static-path-pattern: /static/**servlet:multipart:max-file-size: 10MBmax-request-size: 10MBdatasource:type: com.alibaba.druid.pool.DruidDataSourcedriverClassName: org.postgresql.Driverurl: jdbc:postgresql://127.0.0.1:5432/test?useUnicodetruecharacterEncodingutf-8useSSLfalseserverTimezoneAsia/Shanghaiusername: postgrespassword: root123druid:initialSize: 5minIdle: 5maxActive: 20maxWait: 60000timeBetweenEvictionRunsMillis: 60000minEvictableIdleTimeMillis: 300000validationQuery: SELECT 1testWhileIdle: truetestOnBorrow: falsetestOnReturn: falsefilters: stat,wall,slf4j# 通过connectProperties属性来打开mergeSql功能慢SQL记录connectionProperties: druid.stat.mergeSql\true;druid.stat.slowSqlMillis\5000# 配置DruidStatFilterweb-stat-filter:enabled: trueurl-pattern: /*exclusions: *.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*,/system/druid/*# 配置DruidStatViewServletstat-view-servlet:enabled: trueurl-pattern: /system/druid/*# IP白名单(没有配置或者为空则允许所有访问)allow: localhost,127.0.0.1,192.168.*# IP黑名单 (存在共同时deny优先于allow)deny: 10.1.*# 禁用HTML页面上的“Reset All”功能reset-enable: false# 登录名login-username: admin# 登录密码login-password: 123456