druid-spring-boot-autoconfigure

druid integration with springboot.

License

License

Categories

Categories

Spring Boot Container Microservices Auto Application Layer Libs Code Generators config Configuration druid Data Databases
GroupId

GroupId

com.cuisongliu
ArtifactId

ArtifactId

druid-spring-boot-autoconfigure
Last Version

Last Version

1.3
Release Date

Release Date

Type

Type

jar
Description

Description

druid-spring-boot-autoconfigure
druid integration with springboot.
Project URL

Project URL

https://github.com/cuisongliu/druid-boot-starter
Source Code Management

Source Code Management

https://github.com/cuisongliu/druid-boot-starter

Download druid-spring-boot-autoconfigure

How to add to project

<!-- https://jarcasting.com/artifacts/com.cuisongliu/druid-spring-boot-autoconfigure/ -->
<dependency>
    <groupId>com.cuisongliu</groupId>
    <artifactId>druid-spring-boot-autoconfigure</artifactId>
    <version>1.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.cuisongliu/druid-spring-boot-autoconfigure/
implementation 'com.cuisongliu:druid-spring-boot-autoconfigure:1.3'
// https://jarcasting.com/artifacts/com.cuisongliu/druid-spring-boot-autoconfigure/
implementation ("com.cuisongliu:druid-spring-boot-autoconfigure:1.3")
'com.cuisongliu:druid-spring-boot-autoconfigure:jar:1.3'
<dependency org="com.cuisongliu" name="druid-spring-boot-autoconfigure" rev="1.3">
  <artifact name="druid-spring-boot-autoconfigure" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.cuisongliu', module='druid-spring-boot-autoconfigure', version='1.3')
)
libraryDependencies += "com.cuisongliu" % "druid-spring-boot-autoconfigure" % "1.3"
[com.cuisongliu/druid-spring-boot-autoconfigure "1.3"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Build Status Dependency Status license license

Druid integration with springboot

Druid-Spring-Boot-Starter 帮助你集成通用 Druid 到 Spring Boot。

Druid-Spring-Boot-Starter will help you use Druid with Spring Boot.

How to use

maven

在pom.xml加入nexus资源库(解决中国访问慢的问题,已经加入中央仓库)

Add the following nexus repository(fix china access slow problem,already append to central nexus.) to your pom.xml:

<repositories>
    <repository>
        <id>nexus</id>
        <name>nexus</name>
        <url>http://maven.cuisongliu.com/content/groups/public</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

在pom.xml加入依赖

Add the following dependency to your pom.xml:

<dependency>
       <groupId>com.alibaba</groupId>
       <artifactId>druid</artifactId>
       <version>1.1.5</version>
</dependency>
<dependency>
   <groupId>com.cuisongliu</groupId>
   <artifactId>druid-spring-boot-starter</artifactId>
   <version>1.3</version>
 </dependency>

gradle

在build.gradle加入nexus资源库(解决中国访问慢的问题,已经加入中央仓库)

Add the following nexus repository(fix china access slow problem,already append to central nexus.) to your build.gradle:

allprojects {
    repositories {
        mavenLocal()
        maven { url "http://maven.cuisongliu.com/content/groups/public" }
        mavenCentral()
        jcenter()
    }
}

在build.gradle加入依赖

Add the following dependency to your build.gradle:

compile "com.alibaba:druid:1+"
compile "com.cuisongliu:druid-spring-boot-starter:1+"

springboot properties set

在application.properties 或者application.yml加入相关参数

at application.properties or application.yml append some properties.

properties IsNull? Defaults
spring.datasource.url no null
spring.datasource.username no null
spring.datasource.password no null
spring.datasource.druid.max-active yes 8
spring.datasource.druid.min-idle yes 0
spring.datasource.druid.initial-size yes 0
spring.datasource.druid.max-wait yes -1
spring.datasource.druid.time-between-eviction-runs-millis yes 60 * 1000L
spring.datasource.druid.max-open-prepared-statements yes -1
spring.datasource.druid.test-on-borrow yes false
spring.datasource.druid.validation-query yes null
spring.datasource.druid.test-on-return yes false
spring.datasource.druid.test-while-idle yes true
spring.datasource.druid.pool-prepared-statements yes false
spring.datasource.druid.filters yes false
spring.datasource.druid.max-pool-prepared-statement-per-connection-size yes -1
spring.datasource.druid.validation-query-timeout yes -1
spring.datasource.druid.min-evictable-idle-time-millis yes 1000L * 60L * 30L
spring.datasource.druid.connection-properties yes null

sql slow config:

spring:
 datasource:
    druid:
      connection-properties:
        - druid.stat.mergeSql=true
        - druid.stat.slowSqlMillis=5000

servlet properties

properties IsNull? Defaults
spring.datasource.druid.servlet.enable yes true
spring.datasource.druid.servlet.url-mappings yes /druid/*
spring.datasource.druid.servlet.allow yes null
spring.datasource.druid.servlet.deny yes null
spring.datasource.druid.servlet.login-username yes null
spring.datasource.druid.servlet.login-password yes null
spring.datasource.druid.servlet.reset-enable yes null

filter properties

properties IsNull? Defaults
spring.datasource.druid.servlet.enable yes false
spring.datasource.druid.servlet.exclusions yes .js,.gif,.jpg,.png,.css,.ico,/druid/*
spring.datasource.druid.servlet.url-pattern yes /*
spring.datasource.druid.servlet.session-stat-max-count yes 1000
spring.datasource.druid.servlet.session-stat-enable yes false
spring.datasource.druid.servlet.principal-session-name yes USER_SESSION
spring.datasource.druid.servlet.principal-cookie-name yes USER_COOKIE
spring.datasource.druid.servlet.profile-enable yes true

stat properties

properties IsNull? Defaults
spring.datasource.druid.stat.enable yes false
spring.datasource.druid.stat.aop-types yes null
spring.datasource.druid.stat.target-bean-type yes null
spring.datasource.druid.stat.bean-names yes null
/spring.datasource.druid.stat.patterns yes null

spring.datasource.druid.stat.aop-types 待选值有[ type,name,pointcut ]

当enable=true时候,aop-types必须有type或者name的其中一项.

  • 当aop-types有name值时,bean-names不能为空.
  • 当aop-types有type值时,target-bean-type不能为空.
  • 当aop-types有pointcut值时,patterns不能为空.

spring.datasource.druid.stat.aop-types selected value is [ type,name,pointcut ]

When enable=true , aop-types must have either type or name.

  • When aop-types has name value, bean-names can not be null.
  • When aop-types have type values, target-bean-type can not be empty.
  • When aop-types have pointcut values, patterns can not be empty.

Example

spring:
  datasource:
    url: xxx
    username: xxx
    password: xxx
    druid:
          filters: stat,wall,log4j
          connection-properties:
            - druid.stat.mergeSql=true
            - druid.stat.slowSqlMillis=5000
          filter:
            enable: true
            principal-session-name: session_admin
            profile-enable: true
            principal-cookie-name: session_admin
            session-stat-enable: true
          stat:
            enable: true
            aop-type: 
               - name
               - type
               - pointcut
            target-bean-type: com.cuisongliu.springboot.core.mapper.MyMapper
            bean-names:
               - UserMapper
               - userMapper
            patterns:
              - com.xinyuewulian.mapper.*
              - com.xinyuewulian.service.*

Acknowledgments

druid.

Versions

Version
1.3
1.2
1.1.0
1.0.31.06
1.0.31.05
1.0.31.04
1.0.31.03
1.0.31.02
1.0.31.01
1.0.31