Open SERE026 opened 7 years ago
1.1.1 和1.1.3,1.1.5 版本的兼容性问题
@lihengming 看看是怎么回事
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
失效是因为你的 Spring Cloud Config 配置有问题,因为本地配置文件是没问题的,你看看是不是 Spring Cloud Config 根本没有加载到远程的配置文件。
@ConfigurationProperties("spring.datasource.druid") 此注解再和spring-cloud-config一起使用时失效