1
0
mirror of https://github.com/drtrang/druid-spring-boot.git synced 2026-09-24 02:35:09 +00:00
This commit is contained in:
trang
2017-10-31 11:29:40 +08:00
parent ace1cdb599
commit d87e0750c3
19 changed files with 106 additions and 45 deletions

View File

@@ -1,5 +1,15 @@
# Changelog
### 1.1.1
1. 新增 `statement-sql-format-option` 的代码提示
### 1.1.0
1. 新增 `druid-spring-boot-actuator-starter` 模块
3. 更改包名称为 `com.github.trang.druid.autoconfigure`
4. 更改数据源名称为 `DruidDataSource2`
2. 优化 Auto-configure Bean 的加载条件
5. 优化 Maven 依赖
### 1.0.3
1. 新增 ConfigFilter 的自动配置,替换 Druid 默认的 `connectionProperties` 方式
2. 修复 `spring.datasource.schema` 会执行两次的 bug

View File

@@ -14,14 +14,15 @@ Druid Spring Boot Starter 将帮助你在 Spring Boot 中使用 Druid。
<dependency>
<groupId>com.github.drtrang</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</dependency>
```
## NEW !
1. 新增 `druid-spring-boot-actuator-starter`
1. 新增 ConfigFilter 的自动配置,替换 Druid 默认的 `connectionProperties` 方式
2. 完美支持多数据源 [ISSUE #2](https://github.com/drtrang/druid-spring-boot/issues/2)
1. 新增 `statement-sql-format-option` 的代码提示
2. 新增 `druid-spring-boot-actuator-starter`
3. 新增 ConfigFilter 的自动配置,替换 Druid 默认的 `connectionProperties` 方式
4. 完美支持多数据源 [ISSUE #2](https://github.com/drtrang/druid-spring-boot/issues/2)
## 配置
@@ -96,6 +97,8 @@ spring:
### 配置示例
[application.yml](https://github.com/drtrang/druid-spring-boot/blob/master/druid-spring-boot-samples/src/main/resources/application.yml)
### 全配置说明
## 自动提示
Druid Spring Boot Starter 基于 `spring-boot-configuration-processor` 模块,支持 IDE 的自动提示。

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>com.github.drtrang</groupId>
<artifactId>druid-spring-boot</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>
<artifactId>druid-spring-boot-actuator-autoconfigure</artifactId>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>com.github.drtrang</groupId>
<artifactId>druid-spring-boot</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>
<artifactId>druid-spring-boot-actuator-starter</artifactId>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>com.github.drtrang</groupId>
<artifactId>druid-spring-boot</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>
<artifactId>druid-spring-boot-actuator</artifactId>

View File

@@ -19,11 +19,11 @@ public class DruidDataSourceEndpoint extends AbstractEndpoint<List<Map<String, O
super("druid");
}
private static final DruidStatManagerFacade statManager = DruidStatManagerFacade.getInstance();
private static final DruidStatManagerFacade STAT_MANAGER = DruidStatManagerFacade.getInstance();
@Override
public List<Map<String, Object>> invoke() {
return statManager.getDataSourceStatDataList();
return STAT_MANAGER.getDataSourceStatDataList();
}
}

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>com.github.drtrang</groupId>
<artifactId>druid-spring-boot</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>
<artifactId>druid-spring-boot-autoconfigure</artifactId>

View File

@@ -31,7 +31,7 @@ public abstract class DruidDataSource2Support extends DruidDataSource {
@Autowired
private DruidDataSourceProperties druidDataSourceProperties;
@Autowired
private Optional<List<FilterAdapter>> druidFilters;
private List<FilterAdapter> druidFilters;
@PostConstruct
public void initDruidParentProperties() {
@@ -72,11 +72,14 @@ public abstract class DruidDataSource2Support extends DruidDataSource {
}
private void initFilters() {
List<Filter> filters = super.getProxyFilters();
druidFilters.ifPresent(dfs -> dfs.stream()
.filter(Objects::nonNull)
.filter(filter -> !filters.contains(filter))
.forEach(filters::add));
List<Filter> proxyFilters = super.getProxyFilters();
Optional.ofNullable(druidFilters)
.filter(filters -> !filters.isEmpty())
.ifPresent(dfs -> dfs.stream()
.filter(Objects::nonNull)
.filter(filter -> !proxyFilters.contains(filter))
.forEach(proxyFilters::add)
);
}
}

View File

@@ -43,60 +43,60 @@ public class DruidDataSourceProperties {
@Getter@Setter
public static class DruidConfigFilterProperties {
// 是否开启 druid config-filter默认否
/** 是否开启 druid config-filter默认否 */
private boolean enabled;
// 密钥地址
/** 密钥地址 */
private String file;
// 加密密钥
/** 加密密钥 */
private String key;
}
@Getter
@Setter
public static class DruidStatViewServletProperties {
// 是否开启 druid 的数据统计页面,默认否
/** 是否开启 druid 的数据统计页面,默认否 */
private boolean enabled;
// servlet 的映射规则,默认访问 "http://xxx/druid/"
/** servlet 的映射规则,默认访问 "http:/**xxx/druid/" */
private String urlMappings = "/druid/*";
// druid 统计页面的登陆用户名
/** druid 统计页面的登陆用户名 */
private String loginUsername;
// druid 统计页面的登陆密码
/** druid 统计页面的登陆密码 */
private String loginPassword;
// druid 统计页面的访问白名单,默认允许所有人访问
/** druid 统计页面的访问白名单,默认允许所有人访问 */
private String allow;
// druid 统计页面的访问黑名单,优先于白名单
/** druid 统计页面的访问黑名单,优先于白名单 */
private String deny;
// 是否允许清空统计数据,默认否
/** 是否允许清空统计数据,默认否 */
private boolean resetEnable;
}
@Getter
@Setter
public static class DruidWebStatProperties {
// 是否开启 web-jdbc 监控,默认否
/** 是否开启 web-jdbc 监控,默认否 */
private boolean enabled;
// 过滤器 url 的映射规则
/** 过滤器 url 的映射规则 */
private String urlPatterns = "/*";
// 过滤器 url 的排除规则
/** 过滤器 url 的排除规则 */
private String exclusions = "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*";
// 是否开启 session 统计,默认否
/** 是否开启 session 统计,默认否 */
private boolean sessionStatEnable;
// session 统计的最大值,默认值 1000
/** session 统计的最大值,默认值 1000 */
private Integer sessionStatMaxCount = 1000;
// 配置当前 session 的用户
/** 配置当前 session 的用户 */
private String principalSessionName;
// 配置当前 cookie 的用户
/** 配置当前 cookie 的用户 */
private String principalCookieName;
// 是否开启监控单个 url 调用的 sql 列表,默认是
/** 是否开启监控单个 url 调用的 sql 列表,默认是 */
private boolean profileEnable = true;
}
@Getter
@Setter
public static class DruidAopStatProperties {
// 是否开启基于 aop 的监控,默认否
/** 是否开启基于 aop 的监控,默认否 */
private boolean enabled;
// aop 拦截规则
/** aop 拦截规则 */
private String[] patterns;
}

View File

@@ -62,6 +62,30 @@
"description": "Whether or not druid stat-view-servlet are enabled.",
"sourceType": "com.github.trang.druid.autoconfigure.properties.DruidDataSourceProperties$DruidStatViewServletProperties",
"defaultValue": false
},
{
"name": "spring.datasource.druid.slf4j.statement-sql-format-option.upp-case",
"type": "java.lang.Boolean",
"sourceType": "com.alibaba.druid.sql.SQLUtils$FormatOption",
"defaultValue": false
},
{
"name": "spring.datasource.druid.slf4j.statement-sql-format-option.pretty-format",
"type": "java.lang.Boolean",
"sourceType": "com.alibaba.druid.sql.SQLUtils$FormatOption",
"defaultValue": true
},
{
"name": "spring.datasource.druid.slf4j.statement-sql-format-option.desensitize",
"type": "java.lang.Boolean",
"sourceType": "com.alibaba.druid.sql.SQLUtils$FormatOption",
"defaultValue": false
},
{
"name": "spring.datasource.druid.slf4j.statement-sql-format-option.parameterized",
"type": "java.lang.Boolean",
"sourceType": "com.alibaba.druid.sql.SQLUtils$FormatOption",
"defaultValue": false
}
],
"hints": [

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>com.github.drtrang</groupId>
<artifactId>druid-spring-boot</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>
<artifactId>druid-spring-boot-samples</artifactId>

View File

@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
/**
* DruidSpringBootStarterApplication
@@ -22,6 +23,8 @@ public class DruidSpringBootStarterApplication implements CommandLineRunner {
SpringApplication.run(DruidSpringBootStarterApplication.class, args);
}
@Autowired
private ApplicationContext applicationContext;
@Autowired
private CityMapper cityMapper;

View File

@@ -49,7 +49,7 @@ public class SpringDataSourceConfig {
@Bean
@Primary
public DynamicDataSource dataSource(DruidDataSource firstDataSource, DruidDataSource secondDataSource) {
Map<String, DataSource> targetDataSources = new HashMap<>();
Map<String, DataSource> targetDataSources = new HashMap<>(8);
targetDataSources.put(firstDataSource.getName(), firstDataSource);
targetDataSources.put(secondDataSource.getName(), secondDataSource);
return new DynamicDataSource(firstDataSource, targetDataSources);

View File

@@ -5,6 +5,11 @@ import com.github.trang.druid.model.City;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* CityController
*
* @author trang
*/
@RestController
@RequestMapping("/city")
public class CityController {

View File

@@ -7,6 +7,11 @@ import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* CityMapper
*
* @author trang
*/
@Mapper
public interface CityMapper {

View File

@@ -2,6 +2,11 @@ package com.github.trang.druid.model;
import java.io.Serializable;
/**
* City
*
* @author trang
*/
public class City implements Serializable {
private static final long serialVersionUID = 1L;

View File

@@ -46,9 +46,12 @@ spring:
enabled: true
connection-log-enabled: false
connection-log-error-enabled: true
statement-log-enabled: false
statement-log-enabled: true
statement-log-error-enabled: true
statement-sql-pretty-format: true
statement-sql-format-option:
upp-case: true
pretty-format: false
statement-sql-pretty-format: false
statement-executable-sql-log-enable: true
result-set-log-enabled: false
result-set-log-error-enabled: true
@@ -58,7 +61,7 @@ spring:
log-violation: true
throw-exception: false
config:
select-all-column-allow: false
delete-where-none-check: true
config:
enabled: true
aop-stat:

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>com.github.drtrang</groupId>
<artifactId>druid-spring-boot</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>
<artifactId>druid-spring-boot-starter</artifactId>

View File

@@ -5,7 +5,7 @@
<groupId>com.github.drtrang</groupId>
<artifactId>druid-spring-boot</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<packaging>pom</packaging>
<name>Druid Spring Boot Starter</name>
@@ -48,9 +48,9 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<!-- 基础依赖 -->
<druid.version>1.1.3</druid.version>
<druid.version>1.1.5</druid.version>
<mybatis-spring-boot-starter.version>1.3.1</mybatis-spring-boot-starter.version>
<spring-boot.version>1.5.7.RELEASE</spring-boot.version>
<spring-boot.version>1.5.8.RELEASE</spring-boot.version>
<!-- Maven 插件 -->
<maven-dependency-plugin.version>3.0.2</maven-dependency-plugin.version>
<maven-clean-plugin.version>3.0.0</maven-clean-plugin.version>