You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/11/16 09:40:37 UTC
[GitHub] [shardingsphere] qsLI opened a new issue #8174: No JavaBean properties found in com.sun.proxy.$Proxy203
qsLI opened a new issue #8174:
URL: https://github.com/apache/shardingsphere/issues/8174
## Bug Report
**For English only**, other languages will not accept.
Before report a bug, make sure you have:
- Searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues).
- Read documentation: [ShardingSphere Doc](https://shardingsphere.apache.org/document/current/en/overview).
Please pay attention on issues you submitted, because we maybe need more details.
If no response anymore and we cannot reproduce it on current information, we will **close it**.
Please answer these questions before submitting your issue. Thanks!
### Which version of ShardingSphere did you use?
4.1.1
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
shardingSphere-JDBC
### Expected behavior
no exception
### Actual behavior
Caused by: org.yaml.snakeyaml.error.YAMLException: No JavaBean properties found in com.sun.proxy.$Proxy203
at org.yaml.snakeyaml.introspector.PropertyUtils.getPropertiesMap(PropertyUtils.java:115)
at org.yaml.snakeyaml.introspector.PropertyUtils.createPropertySet(PropertyUtils.java:168)
at org.yaml.snakeyaml.introspector.PropertyUtils.getProperties(PropertyUtils.java:161)
at org.yaml.snakeyaml.introspector.PropertyUtils.getProperties(PropertyUtils.java:154)
at org.yaml.snakeyaml.representer.Representer.getProperties(Representer.java:271)
at org.yaml.snakeyaml.representer.Representer$RepresentJavaBean.representData(Representer.java:74)
at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:105)
at org.yaml.snakeyaml.representer.BaseRepresenter.representMapping(BaseRepresenter.java:156)
at org.yaml.snakeyaml.representer.SafeRepresenter$RepresentMap.representData(SafeRepresenter.java:314)
at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:94)
at org.yaml.snakeyaml.representer.Representer.representJavaBeanProperty(Representer.java:147)
at org.apache.shardingsphere.core.yaml.engine.DefaultYamlRepresenter.representJavaBeanProperty(DefaultYamlRepresenter.java:39)
at org.yaml.snakeyaml.representer.Representer.representJavaBean(Representer.java:105)
at org.yaml.snakeyaml.representer.Representer$RepresentJavaBean.representData(Representer.java:74)
at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:105)
at org.yaml.snakeyaml.representer.Representer.representJavaBeanProperty(Representer.java:147)
at org.apache.shardingsphere.core.yaml.engine.DefaultYamlRepresenter.representJavaBeanProperty(DefaultYamlRepresenter.java:39)
at org.yaml.snakeyaml.representer.Representer.representJavaBean(Representer.java:105)
at org.yaml.snakeyaml.representer.Representer$RepresentJavaBean.representData(Representer.java:74)
at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:105)
at org.yaml.snakeyaml.representer.BaseRepresenter.represent(BaseRepresenter.java:64)
at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:306)
at org.yaml.snakeyaml.Yaml.dumpAs(Yaml.java:363)
at org.yaml.snakeyaml.Yaml.dumpAsMap(Yaml.java:388)
at org.apache.shardingsphere.core.yaml.engine.YamlEngine.marshal(YamlEngine.java:119)
at org.apache.shardingsphere.core.config.log.ConfigurationLogger.log(ConfigurationLogger.java:98)
at org.apache.shardingsphere.core.config.log.ConfigurationLogger.log(ConfigurationLogger.java:80)
at org.apache.shardingsphere.shardingjdbc.jdbc.core.context.AbstractRuntimeContext.<init>(AbstractRuntimeContext.java:59)
at org.apache.shardingsphere.shardingjdbc.jdbc.core.context.ShardingRuntimeContext.<init>(ShardingRuntimeContext.java:59)
at org.apache.shardingsphere.shardingjdbc.jdbc.core.datasource.ShardingDataSource.<init>(ShardingDataSource.java:48)
at org.apache.shardingsphere.shardingjdbc.api.ShardingDataSourceFactory.createDataSource(ShardingDataSourceFactory.java:50)
at com.atour.user.framework.configuration.AtourUserShardingDataBaseConfiguration.atourUserDataSource(AtourUserShardingDataBaseConfiguration.java:106)
### Reason analyze (If you can)
snakeyaml cannot marshal proxy class
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
final Properties keyGeneratorProperties = new Properties();
keyGeneratorProperties.put("id.generate.remote", idGenerateRemote);
idGenerateRemote is a proxy class.
### Example codes for reproduce this issue (such as a github link).
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] qsLI commented on issue #8174: No JavaBean properties found in com.sun.proxy.$Proxy203
Posted by GitBox <gi...@apache.org>.
qsLI commented on issue #8174:
URL: https://github.com/apache/shardingsphere/issues/8174#issuecomment-727919667
`Map<String, DataSource> result = new HashMap<>();
result.put("ds0", ds0);
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTableRuleConfigs()
.add(getOrderTableRuleConfiguration());
shardingRuleConfig.getBindingTableGroups()
.add("meb_discount_coupons");
shardingRuleConfig.getBroadcastTables()
.add("meb_discount_type");
shardingRuleConfig.getBroadcastTables()
.add("sys_holiday");
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();
/*
* 开启sql日志
*/
properties.setProperty(ShardingPropertiesConstant.SQL_SHOW.getKey(), String.valueOf(showSql));
properties.setProperty(ShardingPropertiesConstant.MAX_CONNECTIONS_SIZE_PER_QUERY.getKey(), String.valueOf(4));
return ShardingDataSourceFactory.createDataSource(result, shardingRuleConfig, properties);`
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] qsLI edited a comment on issue #8174: No JavaBean properties found in com.sun.proxy.$Proxy203
Posted by GitBox <gi...@apache.org>.
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());
shardingRuleConfig.getBindingTableGroups()
.add("meb_discount_coupons");
shardingRuleConfig.getBroadcastTables()
.add("meb_discount_type");
shardingRuleConfig.getBroadcastTables()
.add("sys_holiday");
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();
/*
* 开启sql日志
*/
properties.setProperty(ShardingPropertiesConstant.SQL_SHOW.getKey(), String.valueOf(showSql));
properties.setProperty(ShardingPropertiesConstant.MAX_CONNECTIONS_SIZE_PER_QUERY.getKey(), String.valueOf(4));
return ShardingDataSourceFactory.createDataSource(result, shardingRuleConfig, properties);
}
```
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] dongzl commented on issue #8174: No JavaBean properties found in com.sun.proxy.$Proxy203
Posted by GitBox <gi...@apache.org>.
dongzl commented on issue #8174:
URL: https://github.com/apache/shardingsphere/issues/8174#issuecomment-728656274
@qsLI , Thanks for your debug code, can you try it with the `master` code, the lastest version is 5.0.0-alpha
ShardingSphere 5.x version has a big different with 4.x, some classes are not exist, can you help us to test it? Thanks.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] terrymanu commented on issue #8174: No JavaBean properties found in com.sun.proxy.$Proxy203
Posted by GitBox <gi...@apache.org>.
terrymanu commented on issue #8174:
URL: https://github.com/apache/shardingsphere/issues/8174#issuecomment-732639192
Closed because of no response
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] qsLI edited a comment on issue #8174: No JavaBean properties found in com.sun.proxy.$Proxy203
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
[GitHub] [shardingsphere] dongzl commented on issue #8174: No JavaBean properties found in com.sun.proxy.$Proxy203
Posted by GitBox <gi...@apache.org>.
dongzl commented on issue #8174:
URL: https://github.com/apache/shardingsphere/issues/8174#issuecomment-727892365
Hi @qsLI , what's your configuration, can you provide it?
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] terrymanu closed issue #8174: No JavaBean properties found in com.sun.proxy.$Proxy203
Posted by GitBox <gi...@apache.org>.
terrymanu closed issue #8174:
URL: https://github.com/apache/shardingsphere/issues/8174
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] qsLI commented on issue #8174: No JavaBean properties found in com.sun.proxy.$Proxy203
Posted by GitBox <gi...@apache.org>.
qsLI commented on issue #8174:
URL: https://github.com/apache/shardingsphere/issues/8174#issuecomment-727933178
Simple code to reproduce
```java
@RunWith(JUnit4ClassRunner.class)
public class MarshalTest implements InvocationHandler {
@Test
public void testMarshal() {
AInterface proxy = (AInterface) Proxy.newProxyInstance(AInterface.class.getClassLoader(),
new Class<?>[] {AInterface.class}, this);
final Properties properties = new Properties();
properties.put("test", proxy);
final String s = new Yaml(new DefaultYamlRepresenter()).dumpAsMap(properties);
System.out.println("s = " + s);
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return null;
}
public static class SimpleImpl implements AInterface {
@Override
public String hello() {
return null;
}
}
public interface AInterface {
String hello();
}
}
```
result:
![image](https://user-images.githubusercontent.com/6805785/99249917-d0733e00-2845-11eb-8d06-140024c2d5f0.png)
----------------------------------------------------------------
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:
users@infra.apache.org