Druid is a database connection pool implementation that combines the strengths of C3P0, DBCP, and PROXOOL, as well as log monitoring, to monitor connection and SQL execution. Today I’m going to focus on integrating Druid with SpringBoot2.0.
In springboot2.0, there is almost no code to change, just importing pom.xml and updating application.properties can easily build Druid.
V modified pom. XML
< the dependency > < groupId > com. Alibaba < / groupId > < artifactId > druid - spring - the boot - starter < / artifactId > < version > 1.1.9 < / version > </dependency>Copy the code
V Directory Structure
V update application. The properties
Druid connection pool configuration https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter # The configuration for spring. Datasource is in application-dev.properties. So direct comments # spring here. The datasource. Druid. Url = JDBC: mysql: / / 10.168.0.24:3306 / dmp_db? UseUnicode = true&characterEncoding = utf8 #spring.datasource.druid.username=root #spring.datasource.druid.password=123456 spring.datasource.druid.initial-size=5 spring.datasource.druid.max-active=20 spring.datasource.druid.min-idle=10 spring.datasource.druid.max-wait=10 spring.datasource.druid.filters=stat,wall spring.datasource.druid.filter.stat.log-slow-sql=true Spring. The datasource. The druid. Filter. Stat. Missile - SQL - millis = 2000 # druid WebStatFilter configuration, description please refer to the druid Wiki, Configuration _ configuration WebStatFilter spring. The datasource. The druid. Web - stat - filter. Enabled = true spring.datasource.druid.web-stat-filter.url-pattern=/* spring.datasource.druid.web-stat-filter.exclusions=*.gif,*.png,*.jpg,*.html,*.js,*.css,*.ico,/druid/* # Druid StatViewServlet configuration, please refer to the Druid Wiki, Configuration _StatViewServlet configuration spring. The datasource. The druid. Stat - view - servlet. Enabled = true spring.datasource.druid.stat-view-servlet.url-pattern=/druid/* spring.datasource.druid.stat-view-servlet.reset-enable=true spring.datasource.druid.stat-view-servlet.login-username=admin spring.datasource.druid.stat-view-servlet.login-password=admin spring.datasource.druid.stat-view-servlet.allow= Spring. The datasource. The druid. Stat - view - servlet. Deny = # Redis configuration, the official reference: https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#common-application-properties # spring. Redis. Database = 0 # spring. Redis. Host = # 127.0.0.1 spring. Redis. Port = 6379 # spring. Redis. Password = #spring.redis.timeout=5000Copy the code
V rendering
V Source code address
Github.com/toutouge/ja…
About the author: Focus on basic platform project development. If you have any questions or suggestions, please feel free to comment! Copyright notice: The copyright of this article belongs to the author and the blog garden, welcome to reprint, but without the consent of the author must retain this statement, and give the original text link in a prominent place on the page of the article. For the record: all comments and messages will be answered as soon as possible. You are welcome to correct your mistakes and make progress together. Or direct private message I support the blogger: if you think the article is helpful to you, you can click on the lower right corner of the article [recommendation]. Your encouragement is the author to adhere to the original and continuous writing of the biggest power! \