当前位置: 首页>>代码示例>>Java>>正文


Java BeanDefinition.getScope方法代码示例

本文整理汇总了Java中org.springframework.beans.factory.config.BeanDefinition.getScope方法的典型用法代码示例。如果您正苦于以下问题:Java BeanDefinition.getScope方法的具体用法?Java BeanDefinition.getScope怎么用?Java BeanDefinition.getScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.beans.factory.config.BeanDefinition的用法示例。


在下文中一共展示了BeanDefinition.getScope方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateJson

import org.springframework.beans.factory.config.BeanDefinition; //导入方法依赖的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();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:70,代码来源:LiveBeansView.java


注:本文中的org.springframework.beans.factory.config.BeanDefinition.getScope方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。