Closed beihaifeiwu closed 7 years ago
对Druid应该没影响吧?
Well, based upon my limited experience, this falls kinda in the middle of irrelevant and relevant... At lease, two aspect falls into concern:
Furthermore, is health indicator endpoint support like the actuator within the reactive web style -- this might be a good plus as spring starter ...
Above are some of my thought, please help review,
thanks & regards.
@beihaifeiwu Druid Spring Boot Starter 1.1.1兼容 Spring Boot 2.0
@pink-lucifer thx
@lihengming , 还有一个地方,SpringBoot监控DataSource时有一个与数据提供者接口,这个Druid也需要提供一下吧 :)
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.autoconfigure.jdbc.metadata.AbstractDataSourcePoolMetadata;
/**
* Created by liupin on 2017/5/4.
*/
public class DruidDataSourcePoolMetadata extends AbstractDataSourcePoolMetadata<DruidDataSource> {
protected DruidDataSourcePoolMetadata(DruidDataSource dataSource) {
super(dataSource);
}
@Override
public Integer getActive() {
return getDataSource().getActiveCount();
}
@Override
public Integer getMax() {
return getDataSource().getMaxActive();
}
@Override
public Integer getMin() {
return getDataSource().getMinIdle();
}
@Override
public String getValidationQuery() {
return getDataSource().getValidationQuery();
}
}
在Configuration里:
@Bean
public DataSourcePoolMetadataProvider druidDataSourcePoolMetadataProvider() {
return dataSource -> new DruidDataSourcePoolMetadata((DruidDataSource) dataSource);
}
@beihaifeiwu
这是结合spring-boot-starter-actuator
用的吧?我试了下不加这些代码也可以显示DruidDataSource的信息(/configprops),你试试。
The following metrics are exposed for each supported DataSource defined in your application:
- The number of active connections (datasource.xxx.active)
- The current usage of the connection pool (datasource.xxx.usage).
@beihaifeiwu 我看了下官方文档关于这部分的说明,就是为了调用spring-boot-starter-actuator
的 /metrics
时显示active和usage用的,感觉这和Druid 监控提供的信息有点重叠,不知道这个东西重要不,另外请问上面配置的max、min、validationQuery在哪里显示?看了下源码,只看到了active和usage。
DataSourcePublicMetrics.java
...
@Override
public Collection<Metric<?>> metrics() {
Set<Metric<?>> metrics = new LinkedHashSet<>();
for (Map.Entry<String, DataSourcePoolMetadata> entry : this.metadataByPrefix
.entrySet()) {
String prefix = entry.getKey();
prefix = (prefix.endsWith(".") ? prefix : prefix + ".");
DataSourcePoolMetadata metadata = entry.getValue();
addMetric(metrics, prefix + "active", metadata.getActive());
addMetric(metrics, prefix + "usage", metadata.getUsage());
}
return metrics;
}
@lihengming 多谢回复,确实只是使用了两个属性,这部分我并没有深入,这个issue我关闭了:)
@beihaifeiwu :)我再看看吧,如果人畜无害的话就加上,万一有人用到这玩意呢,毕竟DataSourcePoolMetadataProvidersConfiguration
为其他数据源都配置了这个,感谢提醒。
spring boot 2.0.0.M3 集成druid-spring-boot-starter 1.1.3时报以下异常: Description:
Binding to target [Bindable@4507e03f type = ?, value = 'none', annotations = array
Reason: Failed to bind properties under 'spring.datasource.druid.connection-init-sqls[0]' to ?
Action:
配置为: @Bean @ConfigurationProperties(prefix = "spring.datasource") @ConditionalOnClass(com.alibaba.druid.pool.DruidDataSource.class) public DruidDataSource dataSource() { DruidDataSource datasource = DruidDataSourceBuilder.create().build(); return datasource; } spring: datasource: druid: url: jdbc:mysql://127.0.0.1:3306/authority?useUnicode=true&characterEncoding=utf8 username: root password: root driver-class-name: com.mysql.jdbc.Driver
请问如何解决?
@mattmok
@Primary //数据源名称 @Bean(name="portalDataSource") //松耦合属性分层注解,注意,跟druid整合时,需要忽略无效注入属性ignoreInvalidFields = true,避免注入报错 @ConfigurationProperties(value = "spring.datasource.druid.local",ignoreInvalidFields = true) public DataSource dataSourcePortal(){ return DruidDataSourceBuilder.create().build(); }
我想问下,如果我用的是spring-boot-start-webflux,可以集成druid吗,
SpringBoot 2.0.0版本 API变动了,这个有支持的计划吗?