qsLI edited a comment on issue #8174:
URL: https://github.com/apache/shardingsphere/issues/8174#issuecomment-727919667


   ```java
   @Bean(name = "shardingDateSource")
       public DataSource atourUserDataSource(@Qualifier("ds0") DruidDataSource 
ds0) throws SQLException {
           Map<String, DataSource> result = new HashMap<>();
   
           result.put("ds0", ds0);
           ShardingRuleConfiguration shardingRuleConfig = new 
ShardingRuleConfiguration();
           shardingRuleConfig.getTableRuleConfigs()
               .add(getOrderTableRuleConfiguration());
   
           final Properties keyGeneratorProperties = new Properties();
           keyGeneratorProperties.put("id.generate.remote", idGenerateRemote);
           shardingRuleConfig.setDefaultKeyGeneratorConfig(
               new KeyGeneratorConfiguration("ATOUR-FLAKE", "coupon_id", 
keyGeneratorProperties));
           shardingRuleConfig.setDefaultTableShardingStrategyConfig(new 
InlineShardingStrategyConfiguration("meb_id",
               "meb_discount_coupons_${meb_id % " + shardingTableNodes + "}"));
           Properties properties = new Properties();
   
           properties.setProperty(ShardingPropertiesConstant.SQL_SHOW.getKey(), 
String.valueOf(showSql));
           return ShardingDataSourceFactory.createDataSource(result, 
shardingRuleConfig, properties);
   
       }
   ```
   
   
   The root cause, i found is because `idGenerateRemote` is an proxy type.
   
   ```java
       T proxy = (T) Proxy.newProxyInstance(target.type().getClassLoader(),
           new Class<?>[] {target.type()}, handler);
   ```
   Snakeyaml seems not support proxy type marshal.
   
   
   ```java
    protected Map<String, Property> getPropertiesMap(Class<?> type, BeanAccess 
bAccess) {
           if (propertiesCache.containsKey(type)) {
               return propertiesCache.get(type);
           }
   
           Map<String, Property> properties = new LinkedHashMap<String, 
Property>();
           boolean inaccessableFieldsExist = false;
           switch (bAccess) {
               case FIELD:
                   for (Class<?> c = type; c != null; c = c.getSuperclass()) {
                       for (Field field : c.getDeclaredFields()) {
                           int modifiers = field.getModifiers();
                           if (!Modifier.isStatic(modifiers) && 
!Modifier.isTransient(modifiers)
                                   && !properties.containsKey(field.getName())) 
{
                               properties.put(field.getName(), new 
FieldProperty(field));
                           }
                       }
                   }
                   break;
               default:
                   // add JavaBean properties
                   try {
                       for (PropertyDescriptor property : 
Introspector.getBeanInfo(type)
                               .getPropertyDescriptors()) {
                           Method readMethod = property.getReadMethod();
                           if ((readMethod == null || 
!readMethod.getName().equals("getClass"))
                                   && !isTransient(property)) {
                               properties.put(property.getName(), new 
MethodProperty(property));
                           }
                       }
                   } catch (IntrospectionException e) {
                       throw new YAMLException(e);
                   }
   
                   // add public fields
                   for (Class<?> c = type; c != null; c = c.getSuperclass()) {
                       for (Field field : c.getDeclaredFields()) {
                           int modifiers = field.getModifiers();
                           if (!Modifier.isStatic(modifiers) && 
!Modifier.isTransient(modifiers)) {
                               if (Modifier.isPublic(modifiers)) {
                                   properties.put(field.getName(), new 
FieldProperty(field));
                               } else {
                                   inaccessableFieldsExist = true;
                               }
                           }
                       }
                   }
                   break;
           }
           if (properties.isEmpty() && inaccessableFieldsExist) {
              // here it throws
               throw new YAMLException("No JavaBean properties found in " + 
type.getName());
           }
           propertiesCache.put(type, properties);
           return properties;
       }
   ```
   
   shardingsphere code location:  
org.apache.shardingsphere.core.config.log.ConfigurationLogger#log(org.apache.shardingsphere.api.config.sharding.ShardingRuleConfiguration)
   
   ```java
   /**
        * log ShardingRuleConfiguration.
        *
        * @param shardingRuleConfiguration shardingRule configuration
        */
       public static void log(final ShardingRuleConfiguration 
shardingRuleConfiguration) {
           if (null == shardingRuleConfiguration) {
               return;
           }
           log(shardingRuleConfiguration.getClass().getSimpleName(),
               YamlEngine.marshal(new 
ShardingRuleConfigurationYamlSwapper().swap(shardingRuleConfiguration)));
       }
   ```


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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to