mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge pull request #1938 from lihengming/master
Druid Spring Boot Starter > add embedded database default config support for # 1929
This commit is contained in:
@@ -25,7 +25,7 @@ Druid Spring Boot Starter 用于帮助你在Spring Boot项目中轻松集成Drui
|
||||
spring.datasource.url=
|
||||
spring.datasource.username=
|
||||
spring.datasource.password=
|
||||
# ...其他配置(可选,不是必须的)
|
||||
# ...其他配置(可选,不是必须的,使用内嵌数据库的话上述三项也可省略不填)
|
||||
```
|
||||
|
||||
## 配置属性
|
||||
|
||||
@@ -24,7 +24,7 @@ Spring Boot with Druid support, help you simplify Druid config in Spring Boot.
|
||||
spring.datasource.url=
|
||||
spring.datasource.username=
|
||||
spring.datasource.password=
|
||||
# ...other config (optional)
|
||||
# ...other config (optional, use the embedded database, then the above three items can also be omitted)
|
||||
```
|
||||
## Configuration Properties
|
||||
Druid Spring Boot Starter properties name in full compliance with Druid configuration, you can configure the Druid database connection pool and monitor the configuration properties through the following configuration properties, using default values if not configured.
|
||||
|
||||
+6
-6
@@ -26,8 +26,8 @@ import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.wall.WallFilter;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* @author lihengming [89921218@qq.com]
|
||||
@@ -35,22 +35,22 @@ import org.springframework.core.env.Environment;
|
||||
@ConfigurationProperties("spring.datasource.druid")
|
||||
class DruidDataSourceWrapper extends DruidDataSource implements InitializingBean {
|
||||
@Autowired
|
||||
private Environment env;
|
||||
private DataSourceProperties sourceProperties;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
//if not found prefix 'spring.datasource.druid' jdbc properties ,'spring.datasource' prefix jdbc properties will be used.
|
||||
if (super.getUsername() == null) {
|
||||
super.setUsername(env.getProperty("spring.datasource.username"));
|
||||
super.setUsername(sourceProperties.determineUsername());
|
||||
}
|
||||
if (super.getPassword() == null) {
|
||||
super.setPassword(env.getProperty("spring.datasource.password"));
|
||||
super.setPassword(sourceProperties.determinePassword());
|
||||
}
|
||||
if (super.getUrl() == null) {
|
||||
super.setUrl(env.getProperty("spring.datasource.url"));
|
||||
super.setUrl(sourceProperties.determineUrl());
|
||||
}
|
||||
if (super.getDriverClassName() == null) {
|
||||
super.setDriverClassName(env.getProperty("spring.datasource.driver-class-name"));
|
||||
super.setDriverClassName(sourceProperties.determineDriverClassName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-2
@@ -2,57 +2,67 @@
|
||||
"properties": [
|
||||
{
|
||||
"name": "spring.datasource.druid.connection-properties",
|
||||
"type": "java.lang.String"
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "com.alibaba.druid.pool.DruidDataSource"
|
||||
},
|
||||
{
|
||||
"name": "spring.datasource.druid.filters",
|
||||
"type": "java.lang.String"
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "com.alibaba.druid.pool.DruidDataSource"
|
||||
},
|
||||
{
|
||||
"name": "spring.datasource.druid.filter.stat.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"sourceType": "com.alibaba.druid.spring.boot.autoconfigure.stat.DruidFilterConfiguration",
|
||||
"description": "Enable StatFilter.",
|
||||
"defaultValue": true
|
||||
},
|
||||
{
|
||||
"name": "spring.datasource.druid.filter.config.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"sourceType": "com.alibaba.druid.spring.boot.autoconfigure.stat.DruidFilterConfiguration",
|
||||
"description": "Enable ConfigFilter.",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"name": "spring.datasource.druid.filter.encoding.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"sourceType": "com.alibaba.druid.spring.boot.autoconfigure.stat.DruidFilterConfiguration",
|
||||
"description": "Enable EncodingConvertFilter.",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"name": "spring.datasource.druid.filter.slf4j.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"sourceType": "com.alibaba.druid.spring.boot.autoconfigure.stat.DruidFilterConfiguration",
|
||||
"description": "Enable Slf4jLogFilter.",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"name": "spring.datasource.druid.filter.log4j.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"sourceType": "com.alibaba.druid.spring.boot.autoconfigure.stat.DruidFilterConfiguration",
|
||||
"description": "Enable Log4jFilter.",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"name": "spring.datasource.druid.filter.log4j2.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"sourceType": "com.alibaba.druid.spring.boot.autoconfigure.stat.DruidFilterConfiguration",
|
||||
"description": "Enable Log4j2Filter.",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"name": "spring.datasource.druid.filter.commons-log.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"sourceType": "com.alibaba.druid.spring.boot.autoconfigure.stat.DruidFilterConfiguration",
|
||||
"description": "Enable CommonsLogFilter.",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"name": "spring.datasource.druid.filter.wall.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"sourceType": "com.alibaba.druid.spring.boot.autoconfigure.stat.DruidFilterConfiguration",
|
||||
"description": "Enable WallFilter.",
|
||||
"defaultValue": false
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# 只有下面三个是必填项,其他配置不是必须的
|
||||
# 只有下面三个是必填项(使用内嵌数据库的话这三个也可以不用填),其他配置不是必须的
|
||||
spring.datasource.url=jdbc:h2:file:./demo-db
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=sa
|
||||
@@ -11,19 +11,14 @@ spring.datasource.druid.password=sa
|
||||
spring.datasource.druid.initial-size=5
|
||||
spring.datasource.druid.max-active=10
|
||||
spring.datasource.druid.min-evictable-idle-time-millis=100000
|
||||
spring.datasource.druid.validation-query=select 1
|
||||
spring.datasource.druid.aop-patterns=com.alibaba.druid.spring.boot.demo.service.*
|
||||
|
||||
# 自定义StatFilter 配置
|
||||
# 自定义StatFilter 配置 其他 Filter 不再演示
|
||||
spring.datasource.druid.filter.stat.db-type=h2
|
||||
spring.datasource.druid.filter.stat.log-slow-sql=true
|
||||
spring.datasource.druid.filter.stat.slow-sql-millis=2000
|
||||
|
||||
# 自定义WallFilter 配置,其他 Filter 不再演示
|
||||
spring.datasource.druid.filter.wall.enabled=true
|
||||
spring.datasource.druid.filter.wall.db-type=h2
|
||||
spring.datasource.druid.filter.wall.config.delete-allow=false
|
||||
spring.datasource.druid.filter.wall.config.drop-table-allow=false
|
||||
|
||||
# JPA
|
||||
spring.jpa.show-sql= true
|
||||
spring.jpa.hibernate.ddl-auto=create-drop
|
||||
|
||||
Reference in New Issue
Block a user