当前位置: 首页>>代码示例>>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;未经允许,请勿转载。