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


Java ConditionContext.getBeanFactory方法代碼示例

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


在下文中一共展示了ConditionContext.getBeanFactory方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isWebApplication

import org.springframework.context.annotation.ConditionContext; //導入方法依賴的package包/類
private ConditionOutcome isWebApplication(ConditionContext context,
		AnnotatedTypeMetadata metadata, boolean required) {
	ConditionMessage.Builder message = ConditionMessage.forCondition(
			ConditionalOnWebApplication.class, required ? "(required)" : "");
	if (!ClassUtils.isPresent(WEB_CONTEXT_CLASS, context.getClassLoader())) {
		return ConditionOutcome
				.noMatch(message.didNotFind("web application classes").atAll());
	}
	if (context.getBeanFactory() != null) {
		String[] scopes = context.getBeanFactory().getRegisteredScopeNames();
		if (ObjectUtils.containsElement(scopes, "session")) {
			return ConditionOutcome.match(message.foundExactly("'session' scope"));
		}
	}
	if (context.getEnvironment() instanceof StandardServletEnvironment) {
		return ConditionOutcome
				.match(message.foundExactly("StandardServletEnvironment"));
	}
	if (context.getResourceLoader() instanceof WebApplicationContext) {
		return ConditionOutcome.match(message.foundExactly("WebApplicationContext"));
	}
	return ConditionOutcome.noMatch(message.because("not a web application"));
}
 
開發者ID:lodsve,項目名稱:lodsve-framework,代碼行數:24,代碼來源:OnWebApplicationCondition.java

示例2: getMatchOutcome

import org.springframework.context.annotation.ConditionContext; //導入方法依賴的package包/類
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
	List<String> dispatchServletBeans = Arrays.asList(beanFactory
			.getBeanNamesForType(DispatcherServlet.class, false, false));
	if (dispatchServletBeans.contains(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)) {
		return ConditionOutcome.noMatch("found DispatcherServlet named "
				+ DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
	}
	if (beanFactory.containsBean(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)) {
		return ConditionOutcome.noMatch("found non-DispatcherServlet named "
				+ DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
	}
	if (dispatchServletBeans.isEmpty()) {
		return ConditionOutcome.match("no DispatcherServlet found");
	}
	return ConditionOutcome
			.match("one or more DispatcherServlets found and none is named "
					+ DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:22,代碼來源:DispatcherServletAutoConfiguration.java

示例3: isWebApplication

import org.springframework.context.annotation.ConditionContext; //導入方法依賴的package包/類
private ConditionOutcome isWebApplication(ConditionContext context,
		AnnotatedTypeMetadata metadata) {

	if (!ClassUtils.isPresent(WEB_CONTEXT_CLASS, context.getClassLoader())) {
		return ConditionOutcome.noMatch("web application classes not found");
	}

	if (context.getBeanFactory() != null) {
		String[] scopes = context.getBeanFactory().getRegisteredScopeNames();
		if (ObjectUtils.containsElement(scopes, "session")) {
			return ConditionOutcome.match("found web application 'session' scope");
		}
	}

	if (context.getEnvironment() instanceof StandardServletEnvironment) {
		return ConditionOutcome
				.match("found web application StandardServletEnvironment");
	}

	if (context.getResourceLoader() instanceof WebApplicationContext) {
		return ConditionOutcome.match("found web application WebApplicationContext");
	}

	return ConditionOutcome.noMatch("not a web application");
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:26,代碼來源:OnWebApplicationCondition.java

示例4: matches

import org.springframework.context.annotation.ConditionContext; //導入方法依賴的package包/類
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
    final ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    final String[] beanNames =
            BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, ClientFactory.class);

    for (String beanName : beanNames) {
        if (hasQualifier(beanFactory, beanName)) {
            return false;
        }
    }

    return true;
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:15,代碼來源:CentralDogmaConfiguration.java

示例5: getMatchingBeans

import org.springframework.context.annotation.ConditionContext; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
private List<String> getMatchingBeans(ConditionContext context,
		BeanSearchSpec beans) {
	ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
	if (beans.getStrategy() == SearchStrategy.PARENTS
			|| beans.getStrategy() == SearchStrategy.ANCESTORS) {
		BeanFactory parent = beanFactory.getParentBeanFactory();
		Assert.isInstanceOf(ConfigurableListableBeanFactory.class, parent,
				"Unable to use SearchStrategy.PARENTS");
		beanFactory = (ConfigurableListableBeanFactory) parent;
	}
	if (beanFactory == null) {
		return Collections.emptyList();
	}
	List<String> beanNames = new ArrayList<String>();
	boolean considerHierarchy = beans.getStrategy() != SearchStrategy.CURRENT;
	for (String type : beans.getTypes()) {
		beanNames.addAll(getBeanNamesForType(beanFactory, type,
				context.getClassLoader(), considerHierarchy));
	}
	for (String ignoredType : beans.getIgnoredTypes()) {
		beanNames.removeAll(getBeanNamesForType(beanFactory, ignoredType,
				context.getClassLoader(), considerHierarchy));
	}
	for (String annotation : beans.getAnnotations()) {
		beanNames.addAll(Arrays.asList(getBeanNamesForAnnotation(beanFactory,
				annotation, context.getClassLoader(), considerHierarchy)));
	}
	for (String beanName : beans.getNames()) {
		if (containsBean(beanFactory, beanName, considerHierarchy)) {
			beanNames.add(beanName);
		}
	}
	return beanNames;
}
 
開發者ID:lodsve,項目名稱:lodsve-framework,代碼行數:36,代碼來源:OnBeanCondition.java

示例6: recordEvaluation

import org.springframework.context.annotation.ConditionContext; //導入方法依賴的package包/類
private void recordEvaluation(ConditionContext context, String classOrMethodName,
		ConditionOutcome outcome) {
	if (context.getBeanFactory() != null) {
		ConditionEvaluationReport.get(context.getBeanFactory())
				.recordConditionEvaluation(classOrMethodName, this, outcome);
	}
}
 
開發者ID:lodsve,項目名稱:lodsve-framework,代碼行數:8,代碼來源:SpringBootCondition.java

示例7: matches

import org.springframework.context.annotation.ConditionContext; //導入方法依賴的package包/類
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
	ListableBeanFactory factory = context.getBeanFactory();
	String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(factory, this.beanType, false, false);
	if (ObjectUtils.isEmpty(names)) {
		logger.debug("No bean of type [" + this.beanType + "]. Conditional configuration applies.");
		return true;
	}
	else {
		logger.debug("Found bean of type [" + this.beanType + "]. Conditional configuration does not apply.");
		return false;
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:13,代碼來源:BeanTypeNotPresentCondition.java

示例8: getMatchingBeans

import org.springframework.context.annotation.ConditionContext; //導入方法依賴的package包/類
private List<String> getMatchingBeans(ConditionContext context,
		BeanSearchSpec beans) {
	ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
	if (beans.getStrategy() == SearchStrategy.PARENTS) {
		BeanFactory parent = beanFactory.getParentBeanFactory();
		Assert.isInstanceOf(ConfigurableListableBeanFactory.class, parent,
				"Unable to use SearchStrategy.PARENTS");
		beanFactory = (ConfigurableListableBeanFactory) parent;
	}
	if (beanFactory == null) {
		return Collections.emptyList();
	}
	List<String> beanNames = new ArrayList<String>();
	boolean considerHierarchy = beans.getStrategy() == SearchStrategy.ALL;
	for (String type : beans.getTypes()) {
		beanNames.addAll(getBeanNamesForType(beanFactory, type,
				context.getClassLoader(), considerHierarchy));
	}
	for (String ignoredType : beans.getIgnoredTypes()) {
		beanNames.removeAll(getBeanNamesForType(beanFactory, ignoredType,
				context.getClassLoader(), considerHierarchy));
	}
	for (String annotation : beans.getAnnotations()) {
		beanNames.addAll(Arrays.asList(getBeanNamesForAnnotation(beanFactory,
				annotation, context.getClassLoader(), considerHierarchy)));
	}
	for (String beanName : beans.getNames()) {
		if (containsBean(beanFactory, beanName, considerHierarchy)) {
			beanNames.add(beanName);
		}
	}
	return beanNames;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:34,代碼來源:OnBeanCondition.java


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