drtrang / druid-spring-boot Goto Github PK
View Code? Open in Web Editor NEWSpring Boot Starter for Druid.
License: Apache License 2.0
Spring Boot Starter for Druid.
License: Apache License 2.0
druid-spring-boot 自 2017/7/11 发布以来已迭代了 8 个 Release 版本,期间对现有代码的不断完善并持续增加新特性,使该项目愈发友好。
目前 druid-spring-boot 的 latest version 为 1.1.3,拥有以下特性:
由于鄙人能力有限,为了该项目的持续发展,现特向广大开发者征集意见与建议,如当前存在的 bug、希望增加的新特性、更合理的实现方式、更规范的项目结构、甚至于更友好的变量命名……来者不拒。
希望大家踊跃留言,以期在使用过程中得到更高的舒适度以及造福更多的人。
web-stat:
enabled: true
url-patterns: /*
# 该属性设置好像无效
exclusions: 99.js
确定能用?
支持多租户吗
这个和Druid 官方的 springboot-starter 有什么区别,我看配置项都一样
https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter
spring boot 从1到2 升级变化挺大,不同版本之间的兼容性也容易出问题,配置文件,引用包不同,都可能出现各种问题。
如果能够提供完整的2.0下的用法,同时理清跟官网的关系就更好了。持续关注中。
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@61fafb74: startup date [Fri Nov 24 13:24:53 CST 2017]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:420)
at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:95)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:240)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:576)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:552)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:953)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:521)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.destroySingletons(FactoryBeanRegistrySupport.java:227)
at org.springframework.beans.factory.support.AbstractBeanFactory.destroySingletons(AbstractBeanFactory.java)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:960)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1035)
at org.springframework.context.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:562)
at org.springframework.context.support.AbstractApplicationContext.jrLockAndRefresh(AbstractApplicationContext.java)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:751)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:387)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1245)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1233)
at com.riversdm.platform.admin.PlatformAdmin.main(PlatformAdmin.java:76)
13:24:54.619 [main] ERROR o.s.boot.SpringApplication - Application startup failed
hi,多数据源那块有具体示例吗?在代码中如何显示指定哪些操作有哪个数据源?(比如selectA走mysql数据源;selectB走阿里ADS数据源)
另外,【dynamic-data-source-demo】中演示的动态数据源和【druid-spring-boot】中的多数据源有什么区别吗?
druid 1.2.4 starter版本
server:
# 服务监听端口
port: 8777
servlet:
# 系统接口前缀
context-path: /api
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
druid:
initialSize: 5
minIdle: 5
maxActive: 100
maxWait: 60000
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
validationQueryTimeout: 10000
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
# 过滤器设置
filters: stat,wall,log4j2
# StatViewServlet配置
stat-view-servlet:
enabled: true
# 内置监控页面的地址
url-pattern: /druid/*
loginUsername: blank
loginPassword: blank
reset-enable: false
# WebStatFilter配置
web-stat-filter:
enabled: true
url-pattern: /*
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/api/druid/*,/api/swagger-ui.html,/api/swagger-ui/*,/api/swagger-resources/**,/api/v2/api-docs,/api/v3/api-docs,/api/webjars/**"
min-evictable-idle-time-millis: 100000
max-evictable-idle-time-millis: 200000
你好,例如有上面这种配置,会导致单元测试失败,因为使用动态绑定会按ASCII的顺序绑定配置属性,也就是说max 是先于 min执行的,这也是Druid官方Starter放弃动态绑定这种便捷方式的原因之一,如果你有更好的解决方案,可以探讨下。
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.github.trang.druid.DruidAutoConfiguration]; nested exception is java.lang.ClassCastException: java.lang.UnsupportedClassVersionError cannot be cast to [Ljava.lang.Object;
_我采用的是_properties配置方式
Boot版本1.5.4.RELEASE
多数据源是否可以支持,示例上是否可以加上多数据的解决方案?
在yml中设置好max和min值,但是还是会报错,只有注释掉最大值才行
参考:https://blog.csdn.net/qq_26975307/article/details/83819542
首先,我想问一下,你这里是druid 数据源连接池的官方代码仓库吗?
是不是可以对这两个进行官方支持呀,这个并不难,代码也没多少。
特别是spring.datasource.type
由于spring boot 的内嵌数据源由它来进行配置的,如果引入了druid 就没法使用spring boot 提供的配置内嵌数据源了。有时候切换还相当麻烦,如果提供了该支持更好。
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.9</version>
</dependency>
@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)
public class Application3402 {
public static void main(String[] args) {
SpringApplication.run(Application3402.class, args);
}
}
/**
* 实现支持: spring.datasource.type 配置项
* druid 原本没有对该配置项进行支持。
*/
@Configuration
@ConditionalOnMissingBean(DataSource.class)
@AutoConfigureBefore({DataSourceAutoConfiguration.class})
@Import(SuyhDataSourceAutoConfiguration.Druid.class)
@Slf4j
public class SuyhDataSourceAutoConfiguration {
@ConditionalOnClass(DruidDataSource.class)
@ConditionalOnMissingBean(DataSource.class)
@ConditionalOnProperty(name = "spring.datasource.type",
havingValue = "com.alibaba.druid.pool.DruidDataSource",
matchIfMissing = true)
protected static class Druid {
@Bean(initMethod = "init")
@ConfigurationProperties(prefix = "spring.datasource.druid")
public DataSource dataSource() {
log.info("Init DruidDataSource");
return DruidDataSourceBuilder.create().build();
}
}
}
对于DataSourcePoolMetrics
的支持也是比较简单
Hi~
我在Spring Boot 2.1下使用这个组件时遇到个问题:
***************************
APPLICATION FAILED TO START
***************************
Description:
Configuration property name 'spring.datasource.druid.data-sources.commonMaster' is not valid:
Invalid characters: 'M'
Bean: additionConfigController
Reason: Canonical names should be kebab-case ('-' separated), lowercase alpha-numeric characters and must start with a letter
Action:
Modify 'spring.datasource.druid.data-sources.commonMaster' so that it conforms to the canonical names requirements.
提示属性名格式不正确。确认了一下yml里面写的,的确是小写中横线格式的:
spring:
datasource:
druid:
data-sources:
common-master:
...
跟了一下,是初始化数据源对象时候,bind属性操作使用的beanName
拼接,而非最初配置使用的key:
所以这里要么想办法把先前的key传过来,要么再做一次驼峰转小写中横线😂
如下图,因为后面的module版本号都在parent里面,而1.1.9的parent包没有上传到maven**仓库,所以后面的依赖都无法正常使用:
主要是spring boot 1.x的那个parent依赖没有
这么明显不能用的问题,难道就没人发现么
目前示例是根据mybatis来配置的,由于jpa与mybatis在引用数据源及事务方面存在差异,是否能提供一个基于jpa的配置。
谢谢~
spring-projects/spring-boot#22204
this case only used at dev env.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.