taotao365s opened a new issue #13865:
URL: https://github.com/apache/shardingsphere/issues/13865


   ## Question
   
   background: shardingsphere 5.0
   
   
   - application.yml
   
   ````
   
spring.shardingsphere.rules.sharding.tables.t_dict.key-generate-strategy.column=id
   
spring.shardingsphere.rules.sharding.tables.t_dict.key-generate-strategy.key-generator-name=dict_primary_key
   
   
spring.shardingsphere.rules.sharding.key-generators.dict_primary_key.type=BIZ_PRIMARY_KEY
   
spring.shardingsphere.rules.sharding.key-generators.dict_primary_key.props.biz-type=dict
   ````
   
   - BizPrimaryKeyGenerateAlgorithm.java
   
   ````
   public final class BizPrimaryKeyGenerateAlgorithm implements 
KeyGenerateAlgorithm {
   
       @Getter
       @Setter
       private Properties props = new Properties();
   
       private String bizType;
   
       @Override
       public Comparable<?> generateKey() {
           //TODO
       }
   
       @Override
       public void init() {
           this.bizType = props.getProperty("biz-type", "default");
           log.info("init biz type={}", this.bizType);
       }
   
       @Override
       public String getType() {
           return "BIZ_PRIMARY_KEY";
       }
   }
   ````
   
   -  when I set `key-generator-name` is `dict_primary_key`, props is always 
null in BizPrimaryKeyGenerateAlgorithm.java
   -  then I debug it to `PropertyUtil.containPropertyPrefix --> v2`
   
   
   ````
   @SneakyThrows(ReflectiveOperationException.class)
       private static Object v2(final Environment environment, final String 
prefix, final Class<?> targetClass) {
           Class<?> binderClass = 
Class.forName("org.springframework.boot.context.properties.bind.Binder");
           Method getMethod = binderClass.getDeclaredMethod("get", 
Environment.class);
           Method bindMethod = binderClass.getDeclaredMethod("bind", 
String.class, Class.class);
           Object binderObject = getMethod.invoke(null, environment);
           String prefixParam = prefix.endsWith(".") ? prefix.substring(0, 
prefix.length() - 1) : prefix;
           Object bindResultObject = bindMethod.invoke(binderObject, 
prefixParam, targetClass);
           Method resultGetMethod = 
bindResultObject.getClass().getDeclaredMethod("get");
           return resultGetMethod.invoke(bindResultObject);
       }
   ````
   so what does v2 function mean?
   
   
   when I change `key-generator-name` to `dict-primary-key`, props have values 
in BizPrimaryKeyGenerateAlgorithm.java
   
   ````
   
spring.shardingsphere.rules.sharding.tables.t_dict.key-generate-strategy.column=id
   
spring.shardingsphere.rules.sharding.tables.t_dict.key-generate-strategy.key-generator-name=dict-primary-key
   
   
spring.shardingsphere.rules.sharding.key-generators.dict-primary-key.type=BIZ_PRIMARY_KEY
   
spring.shardingsphere.rules.sharding.key-generators.dict-primary-key.props.biz-type=dict
   ````
   
   
   


-- 
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]


Reply via email to