您现在的位置是:首页 > 文章详情

sharding-jdbc不分库策略在springboot的application.properties中的写法

日期:2018-06-05点击:493

sharding-jdbc不分片策略NoneShardingStrategy在springboot中的写法

使用springboot的application.properties来定义分片策略时,

sharding.jdbc.config.sharding.default-database-strategy.none=

这样写会报错

*************************** APPLICATION FAILED TO START *************************** Description: Binding to target io.shardingjdbc.spring.boot.sharding.SpringBootShardingRuleConfigurationProperties@675ffd1d failed: Property: sharding.jdbc.config.sharding.defaultDatabaseStrategy.none Value: Reason: Failed to convert property value of type 'java.lang.String' to required type 'io.shardingjdbc.core.yaml.sharding.strategy.YamlNoneShardingStrategyConfiguration' for property 'defaultDatabaseStrategy.none'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'io.shardingjdbc.core.yaml.sharding.strategy.YamlNoneShardingStrategyConfiguration' for property 'none': no matching editors or conversion strategy found Action: Update your application's configuration 

需要写成

sharding.jdbc.config.sharding.default-database-strategy.none.any=

即,在none后面再加一层随便什么名字。

因为springboot中,使用了@ConfigurationProperties的类,在properties文件中就可以通过 “prefix前缀 . 成员变量名 = 值” 来配置。

如果成员变量还是一个类,就再加一层来配置。即“prefix前缀 . 成员变量名 . 子类成员变量名 = 值”。

特殊的, 如果成员变量是一个类,而它却没有成员变量了(例如amlNoneShardingStrategyConfiguration),那么仍然需要加一层。即“prefix前缀 . 成员变量名 . 任意名 = 值”。

// SpringBootShardingRuleConfigurationProperties.java @ConfigurationProperties(prefix = "sharding.jdbc.config.sharding") public class SpringBootShardingRuleConfigurationProperties extends YamlShardingRuleConfiguration { } // YamlNoneShardingStrategyConfiguration.java public final class YamlNoneShardingStrategyConfiguration implements YamlShardingStrategyConfiguration { }
原文链接:https://yq.aliyun.com/articles/623713
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章