public Mono<List<Map<String, Object>>> databases() {
var result = new ArrayList<Map<String, Object>>();
var dataSources = SpringContextHolder.getApplicationContext().getBeansOfType(DataSource.class);
dataSources.forEach((k, v) -> {
var map = new HashMap<String, Object>();
map.put("beanName", k);
var propertyDescriptors = BeanUtils.getPropertyDescriptors(v.getClass());
for (var propertyDescriptor : propertyDescriptors) {
var method = propertyDescriptor.getReadMethod();
if (null != method && method.getParameterCount() == 0
&& !method.getReturnType().isAssignableFrom(PrintWriter.class)) {
if (!Modifier.isPublic(method.getDeclaringClass().getModifiers())) {
method.setAccessible(true);
}
try {
var value = method.invoke(v);
if (value instanceof Serializable) {
map.put(propertyDescriptor.getName(), value);
}
} catch (Exception e) {
}
}
}
result.add(map);
});
return Mono.justOrEmpty(result);
}
网友评论