alibaba / druid

阿里云计算平台DataWorks(https://help.aliyun.com/document_detail/137663.html) 团队出品,为监控而生的数据库连接池
https://github.com/alibaba/druid/wiki
Apache License 2.0
27.98k stars 8.59k forks source link

1.1.3和1.1.5 DataSource build 多数据源方法不兼容 #2110

Open SERE026 opened 7 years ago

SERE026 commented 7 years ago

@ConfigurationProperties("spring.datasource.druid") 此注解再和spring-cloud-config一起使用时失效

SERE026 commented 7 years ago

1.1.1 和1.1.3,1.1.5 版本的兼容性问题

wenshao commented 7 years ago

@lihengming 看看是怎么回事

SERE026 commented 7 years ago

springcloudconfig 使用 @configurationproperties("spring.datasource.druid") 不生效, 故使用1.1.1 版本的build(env,prefix)方法,代码如下, DruidDataSourceProperties properties = new DruidDataSourceProperties(); properties.setUrl(env.getProperty(prefix + "url")); properties.setUsername(env.getProperty(prefix + "username")); properties.setPassword(env.getProperty(prefix + "password")); properties.setDriverClassName(env.getProperty(prefix + "driver-class-name")); properties.setInitialSize(env.getProperty(prefix + "initial-size", Integer.class)); properties.setMaxActive(env.getProperty(prefix + "max-active", Integer.class)); properties.setMinIdle(env.getProperty(prefix + "min-idle", Integer.class)); properties.setMaxWait(env.getProperty(prefix + "max-wait", Long.class)); properties.setPoolPreparedStatements(env.getProperty(prefix + "pool-prepared-statements", Boolean.class)); properties.setMaxOpenPreparedStatements(env.getProperty(prefix + "max-open-prepared-statements", Integer.class)); properties.setMaxPoolPreparedStatementPerConnectionSize( env.getProperty(prefix + "max-pool-prepared-statement-per-connection-size", Integer.class)); properties.setValidationQuery(env.getProperty(prefix + "validation-query")); properties.setValidationQueryTimeout(env.getProperty(prefix + "validation-query-timeout", Integer.class)); properties.setTestOnBorrow(env.getProperty(prefix + "test-on-borrow", Boolean.class)); properties.setTestOnReturn(env.getProperty(prefix + "test-on-return", Boolean.class)); properties.setTestWhileIdle(env.getProperty(prefix + "test-while-idle", Boolean.class)); properties.setTimeBetweenEvictionRunsMillis(env.getProperty(prefix + "time-between-eviction-runs-millis", Long.class)); properties.setMinEvictableIdleTimeMillis(env.getProperty(prefix + "min-evictable-idle-time-millis", Long.class)); properties.setMaxEvictableIdleTimeMillis(env.getProperty(prefix + "max-evictable-idle-time-millis", Long.class)); properties.setFilters(env.getProperty(prefix + "filters"));

但是 1.1.3和1.1.5版本,此方法注释写着将被弃用,如果使用build()方法,将根据 @configurationproperties("spring.datasource.druid") 去查找信息, 而 springcloudconfig 对此注解不生效 ,配置中心使用的是svn

lihengming commented 6 years ago

失效是因为你的 Spring Cloud Config 配置有问题,因为本地配置文件是没问题的,你看看是不是 Spring Cloud Config 根本没有加载到远程的配置文件。