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


Java ConditionContext.getResourceLoader方法代碼示例

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


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

示例3: getMatchOutcome

import org.springframework.context.annotation.ConditionContext; //導入方法依賴的package包/類
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	MultiValueMap<String, Object> attributes = metadata
			.getAllAnnotationAttributes(ConditionalOnResource.class.getName(), true);
	if (attributes != null) {
		ResourceLoader loader = context.getResourceLoader() == null
				? this.defaultResourceLoader : context.getResourceLoader();
		List<String> locations = new ArrayList<String>();
		collectValues(locations, attributes.get("resources"));
		Assert.isTrue(!locations.isEmpty(),
				"@ConditionalOnResource annotations must specify at least one resource location");
		for (String location : locations) {
			if (!loader
					.getResource(
							context.getEnvironment().resolvePlaceholders(location))
					.exists()) {
				return ConditionOutcome.noMatch("resource not found: " + location);
			}
		}
	}
	return ConditionOutcome.match();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:24,代碼來源:OnResourceCondition.java

示例4: MemberConditions

import org.springframework.context.annotation.ConditionContext; //導入方法依賴的package包/類
MemberConditions(ConditionContext context, String className) {
	this.context = context;
	this.readerFactory = new SimpleMetadataReaderFactory(
			context.getResourceLoader());
	String[] members = getMetadata(className).getMemberClassNames();
	this.memberConditions = getMemberConditions(members);
}
 
開發者ID:lodsve,項目名稱:lodsve-framework,代碼行數:8,代碼來源:AbstractNestedCondition.java

示例5: getMatchOutcome

import org.springframework.context.annotation.ConditionContext; //導入方法依賴的package包/類
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	MultiValueMap<String, Object> attributes = metadata
			.getAllAnnotationAttributes(ConditionalOnResource.class.getName(), true);
	ResourceLoader loader = context.getResourceLoader() == null
			? this.defaultResourceLoader : context.getResourceLoader();
	List<String> locations = new ArrayList<String>();
	collectValues(locations, attributes.get("resources"));
	Assert.isTrue(!locations.isEmpty(),
			"@ConditionalOnResource annotations must specify at "
					+ "least one resource location");
	List<String> missing = new ArrayList<String>();
	for (String location : locations) {
		String resource = context.getEnvironment().resolvePlaceholders(location);
		if (!loader.getResource(resource).exists()) {
			missing.add(location);
		}
	}
	if (!missing.isEmpty()) {
		return ConditionOutcome.noMatch(ConditionMessage
				.forCondition(ConditionalOnResource.class)
				.didNotFind("resource", "resources").items(Style.QUOTE, missing));
	}
	return ConditionOutcome
			.match(ConditionMessage.forCondition(ConditionalOnResource.class)
					.found("location", "locations").items(locations));
}
 
開發者ID:lodsve,項目名稱:lodsve-framework,代碼行數:29,代碼來源:OnResourceCondition.java

示例6: getMatchOutcome

import org.springframework.context.annotation.ConditionContext; //導入方法依賴的package包/類
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	if (!(context.getResourceLoader() instanceof WebApplicationContext)) {
		return ConditionOutcome.noMatch("Non WebApplicationContext");
	}
	ManagementServerPort port = ManagementServerPort.get(context.getEnvironment(),
			context.getBeanFactory());
	return new ConditionOutcome(port == ManagementServerPort.SAME,
			"Management context");
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:12,代碼來源:EndpointWebMvcAutoConfiguration.java


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