本文整理汇总了Java中org.springframework.beans.factory.config.ConfigurableListableBeanFactory.getDependenciesForBean方法的典型用法代码示例。如果您正苦于以下问题:Java ConfigurableListableBeanFactory.getDependenciesForBean方法的具体用法?Java ConfigurableListableBeanFactory.getDependenciesForBean怎么用?Java ConfigurableListableBeanFactory.getDependenciesForBean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.beans.factory.config.ConfigurableListableBeanFactory
的用法示例。
在下文中一共展示了ConfigurableListableBeanFactory.getDependenciesForBean方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBeanDependencies
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //导入方法依赖的package包/类
/**
* Long lists of dependencies indicate low cohesiveness and high coupling. This helps you identify the problematic beans.
* @return map of dependencies for all beans in the context
*/
public Map<String, Set<String>> getBeanDependencies() {
Map<String, Set<String>> beanDeps = new TreeMap<>();
ConfigurableListableBeanFactory factory = context.getBeanFactory();
for(String beanName : factory.getBeanDefinitionNames()) {
if(factory.getBeanDefinition(beanName).isAbstract()) {
continue;
}
String[] dependenciesForBean = factory.getDependenciesForBean(beanName);
Set<String> set = beanDeps.get(beanName);
if(set == null) {
set = new TreeSet<>();
beanDeps.put(beanName, set);
}
for(String dependency : dependenciesForBean) {
set.add(dependency);
}
}
return beanDeps;
}
示例2: generateJson
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //导入方法依赖的package包/类
/**
* Actually generate a JSON snapshot of the beans in the given ApplicationContexts.
* <p>This implementation doesn't use any JSON parsing libraries in order to avoid
* third-party library dependencies. It produces an array of context description
* objects, each containing a context and parent attribute as well as a beans
* attribute with nested bean description objects. Each bean object contains a
* bean, scope, type and resource attribute, as well as a dependencies attribute
* with a nested array of bean names that the present bean depends on.
* @param contexts the set of ApplicationContexts
* @return the JSON document
*/
protected String generateJson(Set<ConfigurableApplicationContext> contexts) {
StringBuilder result = new StringBuilder("[\n");
for (Iterator<ConfigurableApplicationContext> it = contexts.iterator(); it.hasNext();) {
ConfigurableApplicationContext context = it.next();
result.append("{\n\"context\": \"").append(context.getId()).append("\",\n");
if (context.getParent() != null) {
result.append("\"parent\": \"").append(context.getParent().getId()).append("\",\n");
}
else {
result.append("\"parent\": null,\n");
}
result.append("\"beans\": [\n");
ConfigurableListableBeanFactory bf = context.getBeanFactory();
String[] beanNames = bf.getBeanDefinitionNames();
boolean elementAppended = false;
for (String beanName : beanNames) {
BeanDefinition bd = bf.getBeanDefinition(beanName);
if (isBeanEligible(beanName, bd, bf)) {
if (elementAppended) {
result.append(",\n");
}
result.append("{\n\"bean\": \"").append(beanName).append("\",\n");
String scope = bd.getScope();
if (!StringUtils.hasText(scope)) {
scope = BeanDefinition.SCOPE_SINGLETON;
}
result.append("\"scope\": \"").append(scope).append("\",\n");
Class<?> beanType = bf.getType(beanName);
if (beanType != null) {
result.append("\"type\": \"").append(beanType.getName()).append("\",\n");
}
else {
result.append("\"type\": null,\n");
}
String resource = StringUtils.replace(bd.getResourceDescription(), "\\", "/");
result.append("\"resource\": \"").append(resource).append("\",\n");
result.append("\"dependencies\": [");
String[] dependencies = bf.getDependenciesForBean(beanName);
if (dependencies.length > 0) {
result.append("\"");
}
result.append(StringUtils.arrayToDelimitedString(dependencies, "\", \""));
if (dependencies.length > 0) {
result.append("\"");
}
result.append("]\n}");
elementAppended = true;
}
}
result.append("]\n");
result.append("}");
if (it.hasNext()) {
result.append(",\n");
}
}
result.append("]");
return result.toString();
}