strongduanmu commented on a change in pull request #13824: URL: https://github.com/apache/shardingsphere/pull/13824#discussion_r758840438
########## File path: docs/document/content/reference/faq/_index.cn.md ########## @@ -334,3 +334,47 @@ ShardingSphere 中很多功能实现类的加载方式是通过 [SPI](/cn/concep 更多关于 alias 使用方法请参考 [Proxool官网](http://proxool.sourceforge.net/configure.html)。 PS:sourceforge 网站需要翻墙访问。 + +## 29. [其他] 使用 Spring Boot 2.x 集成 ShardingSphere 时,配置文件中的属性设置不生效? + +回答: + +需要特别注意,Spring Boot 2.x 环境下 配置文件的属性名称约束为仅允许小写字母、数字和短横线,即`[a-z][0-9]`和`-`。 + +原因如下: + +Spring Boot 2.x 环境下,ShardingSphere 通过 Binder 来绑定配置文件,属性名称不规范(如:驼峰或下划线等)会导致属性设置不生效从而校验属性值时抛出 `NullPointerException` 异常。参考以下错误示例: + +下划线示例1:database_inline +``` +spring.shardingsphere.rules.sharding.sharding-algorithms.database_inline.type=INLINE +spring.shardingsphere.rules.sharding.sharding-algorithms.database_inline.props.algorithm-expression=ds-$->{user_id % 2} +``` +``` +Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'database_inline': Initialization of bean failed; nested exception is java.lang.NullPointerException: Inline sharding algorithm expression cannot be null. + ... +Caused by: java.lang.NullPointerException: Inline sharding algorithm expression cannot be null. + at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:897) + at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.getAlgorithmExpression(InlineShardingAlgorithm.java:58) + at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.init(InlineShardingAlgorithm.java:52) + at org.apache.shardingsphere.spring.boot.registry.AbstractAlgorithmProvidedBeanRegistry.postProcessAfterInitialization(AbstractAlgorithmProvidedBeanRegistry.java:98) + at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) + ... +``` +驼峰示例2:databaseInline Review comment: @cheese8 `驼峰示例:databaseInline` may be better. ########## File path: docs/document/content/reference/faq/_index.en.md ########## @@ -341,3 +341,47 @@ The followings are core codes from ProxoolDataSource getConnection method in `Pr ``` For more alias usages, please refer to [Proxool](http://proxool.sourceforge.net/configure.html) official website. + +## 29. [Other] The property settings in the configuration file do not take effect when integrating ShardingSphere with Spring Boot 2.x ? + +Answer: + +Note that the property name in the Spring Boot 2.x environment is constrained to allow only lowercase letters, numbers and short transverse lines, ` [a-z] [0-9] ` and ` - `. + +Reasons: + +In the Spring Boot 2.x environment, ShardingSphere binds the properties through Binder, and the unsatisfied property name (such as camel case or underscore.) can throw a `NullPointerException` exception when the property setting does not work to check the property value. Refer to the following error examples: + +underscore case 1: database_inline +``` +spring.shardingsphere.rules.sharding.sharding-algorithms.database_inline.type=INLINE +spring.shardingsphere.rules.sharding.sharding-algorithms.database_inline.props.algorithm-expression=ds-$->{user_id % 2} +``` +``` +Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'database_inline': Initialization of bean failed; nested exception is java.lang.NullPointerException: Inline sharding algorithm expression cannot be null. + ... +Caused by: java.lang.NullPointerException: Inline sharding algorithm expression cannot be null. + at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:897) + at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.getAlgorithmExpression(InlineShardingAlgorithm.java:58) + at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.init(InlineShardingAlgorithm.java:52) + at org.apache.shardingsphere.spring.boot.registry.AbstractAlgorithmProvidedBeanRegistry.postProcessAfterInitialization(AbstractAlgorithmProvidedBeanRegistry.java:98) + at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) + ... +``` +camel case 2:databaseInline Review comment: @cheese8 Camel case:databaseInline ########## File path: docs/document/content/reference/faq/_index.cn.md ########## @@ -334,3 +334,47 @@ ShardingSphere 中很多功能实现类的加载方式是通过 [SPI](/cn/concep 更多关于 alias 使用方法请参考 [Proxool官网](http://proxool.sourceforge.net/configure.html)。 PS:sourceforge 网站需要翻墙访问。 + +## 29. [其他] 使用 Spring Boot 2.x 集成 ShardingSphere 时,配置文件中的属性设置不生效? + +回答: + +需要特别注意,Spring Boot 2.x 环境下 配置文件的属性名称约束为仅允许小写字母、数字和短横线,即`[a-z][0-9]`和`-`。 + +原因如下: + +Spring Boot 2.x 环境下,ShardingSphere 通过 Binder 来绑定配置文件,属性名称不规范(如:驼峰或下划线等)会导致属性设置不生效从而校验属性值时抛出 `NullPointerException` 异常。参考以下错误示例: + +下划线示例1:database_inline +``` +spring.shardingsphere.rules.sharding.sharding-algorithms.database_inline.type=INLINE +spring.shardingsphere.rules.sharding.sharding-algorithms.database_inline.props.algorithm-expression=ds-$->{user_id % 2} +``` +``` +Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'database_inline': Initialization of bean failed; nested exception is java.lang.NullPointerException: Inline sharding algorithm expression cannot be null. + ... +Caused by: java.lang.NullPointerException: Inline sharding algorithm expression cannot be null. + at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:897) + at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.getAlgorithmExpression(InlineShardingAlgorithm.java:58) + at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.init(InlineShardingAlgorithm.java:52) + at org.apache.shardingsphere.spring.boot.registry.AbstractAlgorithmProvidedBeanRegistry.postProcessAfterInitialization(AbstractAlgorithmProvidedBeanRegistry.java:98) + at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) + ... +``` +驼峰示例2:databaseInline +``` +spring.shardingsphere.rules.sharding.sharding-algorithms.databaseInline.type=INLINE +spring.shardingsphere.rules.sharding.sharding-algorithms.databaseInline.props.algorithm-expression=ds-$->{user_id % 2} +``` +``` +Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'databaseInline': Initialization of bean failed; nested exception is java.lang.NullPointerException: Inline sharding algorithm expression cannot be null. + ... +Caused by: java.lang.NullPointerException: Inline sharding algorithm expression cannot be null. + at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:897) + at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.getAlgorithmExpression(InlineShardingAlgorithm.java:58) + at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.init(InlineShardingAlgorithm.java:52) + at org.apache.shardingsphere.spring.boot.registry.AbstractAlgorithmProvidedBeanRegistry.postProcessAfterInitialization(AbstractAlgorithmProvidedBeanRegistry.java:98) + at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) + ... +``` +可从异常栈中分析得到 `AbstractAlgorithmProvidedBeanRegistry.registerBean` 方法调用 `PropertyUtil.containPropertyPrefix(environment, prefix)` 方法判断指定前缀 `prefix` 的配置不存在,而 `PropertyUtil.containPropertyPrefix(environment, prefix)` 方法,在 Spring Boot 2.x 环境下 `v2(environment, prefix, Map.class)` 使用了 Binder 在属性名称不规范(如:驼峰或下划线等)会导致属性设置不生效。 Review comment: @cheese8 `在 Spring Boot 2.x 环境下使用了 Binder,不规范的属性名称(如:驼峰或下划线等)会导致属性设置不生效。` may be better. ########## File path: docs/document/content/reference/faq/_index.cn.md ########## @@ -334,3 +334,47 @@ ShardingSphere 中很多功能实现类的加载方式是通过 [SPI](/cn/concep 更多关于 alias 使用方法请参考 [Proxool官网](http://proxool.sourceforge.net/configure.html)。 PS:sourceforge 网站需要翻墙访问。 + +## 29. [其他] 使用 Spring Boot 2.x 集成 ShardingSphere 时,配置文件中的属性设置不生效? + +回答: + +需要特别注意,Spring Boot 2.x 环境下 配置文件的属性名称约束为仅允许小写字母、数字和短横线,即`[a-z][0-9]`和`-`。 + +原因如下: + +Spring Boot 2.x 环境下,ShardingSphere 通过 Binder 来绑定配置文件,属性名称不规范(如:驼峰或下划线等)会导致属性设置不生效从而校验属性值时抛出 `NullPointerException` 异常。参考以下错误示例: + +下划线示例1:database_inline Review comment: @cheese8 `下划线示例:database_inline` may be better. ########## File path: docs/document/content/reference/faq/_index.cn.md ########## @@ -334,3 +334,47 @@ ShardingSphere 中很多功能实现类的加载方式是通过 [SPI](/cn/concep 更多关于 alias 使用方法请参考 [Proxool官网](http://proxool.sourceforge.net/configure.html)。 PS:sourceforge 网站需要翻墙访问。 + +## 29. [其他] 使用 Spring Boot 2.x 集成 ShardingSphere 时,配置文件中的属性设置不生效? + +回答: + +需要特别注意,Spring Boot 2.x 环境下 配置文件的属性名称约束为仅允许小写字母、数字和短横线,即`[a-z][0-9]`和`-`。 Review comment: @cheese8 Please remove the useless blank between `环境下` and `配置文件`. ########## File path: docs/document/content/reference/faq/_index.en.md ########## @@ -341,3 +341,47 @@ The followings are core codes from ProxoolDataSource getConnection method in `Pr ``` For more alias usages, please refer to [Proxool](http://proxool.sourceforge.net/configure.html) official website. + +## 29. [Other] The property settings in the configuration file do not take effect when integrating ShardingSphere with Spring Boot 2.x ? + +Answer: + +Note that the property name in the Spring Boot 2.x environment is constrained to allow only lowercase letters, numbers and short transverse lines, ` [a-z] [0-9] ` and ` - `. Review comment: @cheese8 `[a-z] [0-9]` and `-` may be better. No extra spaces are required within the symbol ``. ########## File path: docs/document/content/reference/faq/_index.en.md ########## @@ -341,3 +341,47 @@ The followings are core codes from ProxoolDataSource getConnection method in `Pr ``` For more alias usages, please refer to [Proxool](http://proxool.sourceforge.net/configure.html) official website. + +## 29. [Other] The property settings in the configuration file do not take effect when integrating ShardingSphere with Spring Boot 2.x ? + +Answer: + +Note that the property name in the Spring Boot 2.x environment is constrained to allow only lowercase letters, numbers and short transverse lines, ` [a-z] [0-9] ` and ` - `. + +Reasons: + +In the Spring Boot 2.x environment, ShardingSphere binds the properties through Binder, and the unsatisfied property name (such as camel case or underscore.) can throw a `NullPointerException` exception when the property setting does not work to check the property value. Refer to the following error examples: + +underscore case 1: database_inline Review comment: @cheese8 Please modify it to `Underscore case: database_inline` ########## File path: docs/document/content/reference/faq/_index.cn.md ########## @@ -334,3 +334,47 @@ ShardingSphere 中很多功能实现类的加载方式是通过 [SPI](/cn/concep 更多关于 alias 使用方法请参考 [Proxool官网](http://proxool.sourceforge.net/configure.html)。 PS:sourceforge 网站需要翻墙访问。 + +## 29. [其他] 使用 Spring Boot 2.x 集成 ShardingSphere 时,配置文件中的属性设置不生效? + +回答: + +需要特别注意,Spring Boot 2.x 环境下 配置文件的属性名称约束为仅允许小写字母、数字和短横线,即`[a-z][0-9]`和`-`。 + +原因如下: + +Spring Boot 2.x 环境下,ShardingSphere 通过 Binder 来绑定配置文件,属性名称不规范(如:驼峰或下划线等)会导致属性设置不生效从而校验属性值时抛出 `NullPointerException` 异常。参考以下错误示例: + +下划线示例1:database_inline +``` +spring.shardingsphere.rules.sharding.sharding-algorithms.database_inline.type=INLINE +spring.shardingsphere.rules.sharding.sharding-algorithms.database_inline.props.algorithm-expression=ds-$->{user_id % 2} +``` +``` +Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'database_inline': Initialization of bean failed; nested exception is java.lang.NullPointerException: Inline sharding algorithm expression cannot be null. + ... +Caused by: java.lang.NullPointerException: Inline sharding algorithm expression cannot be null. + at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:897) + at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.getAlgorithmExpression(InlineShardingAlgorithm.java:58) + at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.init(InlineShardingAlgorithm.java:52) + at org.apache.shardingsphere.spring.boot.registry.AbstractAlgorithmProvidedBeanRegistry.postProcessAfterInitialization(AbstractAlgorithmProvidedBeanRegistry.java:98) + at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) + ... +``` +驼峰示例2:databaseInline +``` +spring.shardingsphere.rules.sharding.sharding-algorithms.databaseInline.type=INLINE +spring.shardingsphere.rules.sharding.sharding-algorithms.databaseInline.props.algorithm-expression=ds-$->{user_id % 2} +``` +``` +Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'databaseInline': Initialization of bean failed; nested exception is java.lang.NullPointerException: Inline sharding algorithm expression cannot be null. + ... +Caused by: java.lang.NullPointerException: Inline sharding algorithm expression cannot be null. + at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:897) + at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.getAlgorithmExpression(InlineShardingAlgorithm.java:58) + at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.init(InlineShardingAlgorithm.java:52) + at org.apache.shardingsphere.spring.boot.registry.AbstractAlgorithmProvidedBeanRegistry.postProcessAfterInitialization(AbstractAlgorithmProvidedBeanRegistry.java:98) + at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) + ... +``` +可从异常栈中分析得到 `AbstractAlgorithmProvidedBeanRegistry.registerBean` 方法调用 `PropertyUtil.containPropertyPrefix(environment, prefix)` 方法判断指定前缀 `prefix` 的配置不存在,而 `PropertyUtil.containPropertyPrefix(environment, prefix)` 方法,在 Spring Boot 2.x 环境下 `v2(environment, prefix, Map.class)` 使用了 Binder 在属性名称不规范(如:驼峰或下划线等)会导致属性设置不生效。 Review comment: @cheese8 `从异常堆栈中分析可知:` may be better. ########## File path: docs/document/content/reference/faq/_index.cn.md ########## @@ -334,3 +334,47 @@ ShardingSphere 中很多功能实现类的加载方式是通过 [SPI](/cn/concep 更多关于 alias 使用方法请参考 [Proxool官网](http://proxool.sourceforge.net/configure.html)。 PS:sourceforge 网站需要翻墙访问。 + +## 29. [其他] 使用 Spring Boot 2.x 集成 ShardingSphere 时,配置文件中的属性设置不生效? + +回答: + +需要特别注意,Spring Boot 2.x 环境下 配置文件的属性名称约束为仅允许小写字母、数字和短横线,即`[a-z][0-9]`和`-`。 + +原因如下: + +Spring Boot 2.x 环境下,ShardingSphere 通过 Binder 来绑定配置文件,属性名称不规范(如:驼峰或下划线等)会导致属性设置不生效从而校验属性值时抛出 `NullPointerException` 异常。参考以下错误示例: + +下划线示例1:database_inline +``` +spring.shardingsphere.rules.sharding.sharding-algorithms.database_inline.type=INLINE +spring.shardingsphere.rules.sharding.sharding-algorithms.database_inline.props.algorithm-expression=ds-$->{user_id % 2} +``` +``` +Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'database_inline': Initialization of bean failed; nested exception is java.lang.NullPointerException: Inline sharding algorithm expression cannot be null. + ... +Caused by: java.lang.NullPointerException: Inline sharding algorithm expression cannot be null. + at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:897) + at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.getAlgorithmExpression(InlineShardingAlgorithm.java:58) + at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.init(InlineShardingAlgorithm.java:52) + at org.apache.shardingsphere.spring.boot.registry.AbstractAlgorithmProvidedBeanRegistry.postProcessAfterInitialization(AbstractAlgorithmProvidedBeanRegistry.java:98) + at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) + ... +``` +驼峰示例2:databaseInline +``` +spring.shardingsphere.rules.sharding.sharding-algorithms.databaseInline.type=INLINE +spring.shardingsphere.rules.sharding.sharding-algorithms.databaseInline.props.algorithm-expression=ds-$->{user_id % 2} +``` +``` +Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'databaseInline': Initialization of bean failed; nested exception is java.lang.NullPointerException: Inline sharding algorithm expression cannot be null. + ... +Caused by: java.lang.NullPointerException: Inline sharding algorithm expression cannot be null. + at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:897) + at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.getAlgorithmExpression(InlineShardingAlgorithm.java:58) + at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.init(InlineShardingAlgorithm.java:52) + at org.apache.shardingsphere.spring.boot.registry.AbstractAlgorithmProvidedBeanRegistry.postProcessAfterInitialization(AbstractAlgorithmProvidedBeanRegistry.java:98) + at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) + ... +``` +可从异常栈中分析得到 `AbstractAlgorithmProvidedBeanRegistry.registerBean` 方法调用 `PropertyUtil.containPropertyPrefix(environment, prefix)` 方法判断指定前缀 `prefix` 的配置不存在,而 `PropertyUtil.containPropertyPrefix(environment, prefix)` 方法,在 Spring Boot 2.x 环境下 `v2(environment, prefix, Map.class)` 使用了 Binder 在属性名称不规范(如:驼峰或下划线等)会导致属性设置不生效。 Review comment: @cheese8 `...方法判断指定前缀 `prefix` 的配置是否存在,` may be better. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
