當前位置: 首頁>>代碼示例>>Java>>正文


Java ConfigurableListableBeanFactory.getBeanDefinitionNames方法代碼示例

本文整理匯總了Java中org.springframework.beans.factory.config.ConfigurableListableBeanFactory.getBeanDefinitionNames方法的典型用法代碼示例。如果您正苦於以下問題:Java ConfigurableListableBeanFactory.getBeanDefinitionNames方法的具體用法?Java ConfigurableListableBeanFactory.getBeanDefinitionNames怎麽用?Java ConfigurableListableBeanFactory.getBeanDefinitionNames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.beans.factory.config.ConfigurableListableBeanFactory的用法示例。


在下文中一共展示了ConfigurableListableBeanFactory.getBeanDefinitionNames方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
}
 
開發者ID:jillesvangurp,項目名稱:spring-depend,代碼行數:24,代碼來源:SpringDependencyAnalyzer.java

示例2: postProcessBeanFactory

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //導入方法依賴的package包/類
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    logger.info("Look for Errai Service definitions");
    String[] beans = beanFactory.getBeanDefinitionNames();
    for (String beanName : beans) {
        Class<?> beanType = beanFactory.getType(beanName);
        Service service = AnnotationUtils.findAnnotation(beanType, Service.class);
        if (service != null) {
            try {
                ServiceTypeParser serviceTypeParser = new ServiceTypeParser(beanType);
                services.add(new ServiceImplementation(serviceTypeParser, beanName));
                logger.debug("Found Errai Service definition: beanName=" + beanName + ", beanType=" + beanType);
            } catch (NotAService e) {
                logger.warn("Service annotation present but threw NotAServiceException", e);
            }
        }
    }
}
 
開發者ID:expansel,項目名稱:errai-spring-server,代碼行數:19,代碼來源:ErraiApplicationListener.java

示例3: buildComponentMetadataFor

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //導入方法依賴的package包/類
public static List<ComponentMetadata> buildComponentMetadataFor(ConfigurableListableBeanFactory factory) {
	List<ComponentMetadata> metadata = new ArrayList<ComponentMetadata>();
	String[] components = factory.getBeanDefinitionNames();

	for (String beanName : components) {
		BeanDefinition definition = factory.getBeanDefinition(beanName);

		// filter generated definitions
		if (!definition.hasAttribute(PROMOTED_REF)) {
			// add metadata for top-level definitions
			metadata.add(MetadataFactory.buildComponentMetadataFor(beanName, definition));
			// look for nested ones
			metadata.addAll(MetadataFactory.buildNestedComponentMetadataFor(definition));
		}
	}

	return metadata;
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:19,代碼來源:ComponentMetadataFactory.java

示例4: postProcessBeanFactory

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //導入方法依賴的package包/類
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

		boolean trace = log.isTraceEnabled();

		String[] names = beanFactory.getBeanDefinitionNames();
		for (String name : names) {
			BeanDefinition definition = beanFactory.getBeanDefinition(name);
			if (definition.hasAttribute(ParsingUtils.BLUEPRINT_MARKER_NAME)) {
				ConstructorArgumentValues cArgs = definition.getConstructorArgumentValues();
				if (trace)
					log.trace("Inspecting cycles for (blueprint) bean " + name);

				tag(cArgs.getGenericArgumentValues(), name, definition);
				tag(cArgs.getIndexedArgumentValues().values(), name, definition);
			}
		}
	}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:18,代碼來源:CycleOrderingProcessor.java

示例5: postProcessBeanFactory

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //導入方法依賴的package包/類
@Override
public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException {
	LOGGER.debug(() -> "Lookup @Path and @Provider JAX-RS resource in bean factory [" + beanFactory + "]");

	resources = new ArrayList<>();

	for (String name : beanFactory.getBeanDefinitionNames()) {
		try {
			BeanDefinition definition = beanFactory.getBeanDefinition(name);
			if (!definition.isAbstract()) {
				Class<?> beanClass = BeanRegistryUtils.getBeanClass(name, definition, beanFactory, classLoader);
				if (beanClass != null) {
					if (isJaxrsResourceClass(definition, beanClass)) {
						resources.add(new WeakReference<>(beanClass));
						LOGGER.debug(() -> "Found JAX-RS resource class: [" + beanClass.getName() + "]");
					}
				}
			}
		} catch (@SuppressWarnings("unused") NoSuchBeanDefinitionException e) {
			// ignore
		}
	}
}
 
開發者ID:holon-platform,項目名稱:holon-jaxrs,代碼行數:24,代碼來源:JerseyResourcesPostProcessor.java

示例6: postProcessBeanFactory

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //導入方法依賴的package包/類
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    this.beanFactory = beanFactory;
    for (String name : beanFactory.getBeanDefinitionNames()) {
        BeanDefinition definition = beanFactory.getBeanDefinition(name);
        String method = definition.getFactoryMethodName();
        String bean = definition.getFactoryBeanName();
        if (method != null && bean != null) {
            this.beans.put(name, new MetaData(bean, method));
        }
    }
}
 
開發者ID:zouzhirong,項目名稱:configx,代碼行數:13,代碼來源:ConfigurationBeanFactoryMetaData.java

示例7: getServiceDependencies

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //導入方法依賴的package包/類
public Collection<OsgiServiceDependency> getServiceDependencies(BundleContext bundleContext,
		ConfigurableListableBeanFactory beanFactory) throws BeansException, InvalidSyntaxException, BundleException {

	Set<OsgiServiceDependency> dependencies = new LinkedHashSet<OsgiServiceDependency>();

	String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames();
	for (String definitionName : beanDefinitionNames) {
		BeanDefinition definition = beanFactory.getBeanDefinition(definitionName);
		String className = definition.getBeanClassName();
		// Ignore internal stuff
		if (className == null
			|| className.equals(OsgiServiceProxyFactoryBean.class.getName())
			|| className.equals(OsgiServiceFactoryBean.class.getName())
			|| className.equals(OsgiServiceCollectionProxyFactoryBean.class.getName())) {
			continue;
		}
		try {
			Class<?> clazz = Class.forName(className, true, beanFactory.getBeanClassLoader());
			dependencies.addAll(getClassServiceDependencies(clazz, definitionName, definition));
		}
		catch (ClassNotFoundException cnfe) {
			if (logger.isDebugEnabled())
				logger.debug("Could not load class [" + className + "] for ["
						+ bundleContext.getBundle().getSymbolicName() + "]");
		}
	}
	if (logger.isDebugEnabled())
		logger.debug("Processing annotations for [" + bundleContext.getBundle().getSymbolicName() + "] found "
				+ dependencies);

	return dependencies;
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:33,代碼來源:ServiceReferenceDependencyBeanFactoryPostProcessor.java

示例8: processProperties

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //導入方法依賴的package包/類
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
	StringValueResolver valueResolver = new StringValueResolver() {

		@Override
		public String resolveStringValue(String strVal) {
			StringBuffer sb = new StringBuffer(strVal);
			/**
			 * 給變量加上${XXXXXXX}
			 */
			boolean start = strVal.startsWith(Constant.PLACEHOLDER_PREFIX);
			boolean end = strVal.endsWith(Constant.PLACEHOLDER_SUFFIX);
			while(start && end) {
				String key = sb.substring(placeholderPrefix.length(), sb.length() - placeholderSuffix.length());
				String zkValue = ShiZiQiuConfClient.get(key, "");
				logger.info(">>>>>>>>>>> resolved placeholder '" + key + "' to value [" + zkValue + "]");
				sb = new StringBuffer(zkValue);
				start = sb.toString().startsWith(placeholderPrefix);
				end = sb.toString().endsWith(placeholderSuffix);
			}
			return sb.toString();
		}
	};
	BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver);
	String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
	if (null != beanNames && beanNames.length > 0) {
		for (String beanName : beanNames) {
			if(!(beanName.equals(this.beanName)) && beanFactoryToProcess.equals(this.beanFactory)) {
				BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(beanName);
				visitor.visitBeanDefinition(bd);
			}
		}
	}
}
 
開發者ID:shiziqiu,項目名稱:shiziqiu-configuration,代碼行數:35,代碼來源:ShiZiQiuConfPlaceholderConfigurer.java

示例9: 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();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:70,代碼來源:LiveBeansView.java

示例10: postProcessBeanFactory

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //導入方法依賴的package包/類
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
        throws BeansException {

    // get names of all BeanDefinition
    String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames();

    for (String name: beanDefinitionNames) {

        // get BeanDefinition by name
        BeanDefinition beanDefinition = beanFactory.getBeanDefinition(name);

        /* получаем имя класса создавамого бина, чтобы проверить , 
         * содержит ли он аннотацию UnsupportedCameraRoll 
         */ 
        String className = beanDefinition.getBeanClassName();

        try {
            // get class by name
            Class<?> beanClass = Class.forName(className);

            /* пытаемся получить объект аннотации и ее значение,
             * если  класс не содержит данную аннотацию, то  метод вернет null
             */
            UnproducableCameraRoll annotation = beanClass.getAnnotation(UnproducableCameraRoll.class);

            // проверяем, содержал ли класс эту аннотацию
            if (annotation != null) {
                // получаем значение указанное в параметрах аннотации(класс пленки, которую необходимо использовать)
                Class usingCameraRollName =annotation.usingCameraRollClass();
                // меняем класс будущего бина!
                beanDefinition.setBeanClassName(usingCameraRollName.getName());	
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
 
開發者ID:biblelamp,項目名稱:JavaEE,代碼行數:38,代碼來源:UnproducableCameraRollBeanFactoryPostProcessor.java

示例11: postProcessBeanFactory

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //導入方法依賴的package包/類
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
        throws BeansException {

    // get names of all BeanDefinition defined of use
    String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames();

    for (String name: beanDefinitionNames) {
        // get BeanDefinition by name
        BeanDefinition beanDefinition = beanFactory.getBeanDefinition(name);
        System.out.println(beanDefinition.toString());
    }
}
 
開發者ID:biblelamp,項目名稱:JavaEE,代碼行數:13,代碼來源:TestBFPP.java


注:本文中的org.springframework.beans.factory.config.ConfigurableListableBeanFactory.getBeanDefinitionNames方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。